C++ Saved Program: gifted-dog

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <iostream>
using namespace std;
class set
{
    int size_eng,size_french,english[20],french[20];
    int a[20];
public:
    void accept();
    void display();
    //void union_set();
    void intersection();
    //void difference_AB();

};
void set::accept()
{   int i;
    cout<<"\nEnter the no. of people who speak  english are:";
    cin>>size_eng;
    cout<<"\nEnter id's of people speaking english:{}";
    for(i=0;i<size_eng;i++)
    {
        cin >>english[i];
    }

    cout<<"\nEnter the no. of people  who speak french are:";
    cin>>size_french;
    cout<<"\nEnter id's of people speaking french:{}";
    for(i=0;i<size_french;i++)
        {
            cin >>french[i];
        }

}
void set::display()
{
    int i=0;
    cout<<"\npeople who speak english are:"<<size_eng;
    for(i=0;i<size_eng;i++)
{
    cout<<"\nThe id's of people speaking english are:{}"<<english[i];
}
    cout<<"\npeople who speak french are:"<<size_french;
        for(i=0;i<size_french;i++)
    {
        cout<<"\nThe id's of people speaking french are:{}"<<french[i];
    }
}
//void union_set()
//{



//}
void set::intersection()
{
    int i,j;//size_eng,size_french,english[i],french[i];
    for(i=0;i<size_eng;i++)
    {
        for(j=0;j<size_french;j++)
        {


            if(english[i]==french[j])
                {
                    cout<<"people who speak both:"<<english[i];
                    break;
                }


        }

    }

}

int main()
{ int ch;
char ans,y;
set s;
do
    {

    cout<<"MENU\n0.accept\n1.display\n2.intersection\n3.Exit";
    cout<<"Enter choice";
    cin>>ch;
    switch(ch)
    {
    case 0:s.accept();
    break;
    case 1:s.accept();
            s.display();
    break;
    case 2:s.accept();
            s.intersection();
    break;
    case 3:cout<<"\nExit";
    break;
}  cout<<"Do you want to continue y/n:";
    cin>>ans;
}while(ans==y);



    return 0;
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs