Tuesday 30 August 2016

Set Theory implementation using c++


Group A: Assignment no: 01(SPPU Syllabus Assignment no: 01)
Problem Statement:
In Second year Computer Engineering class of M students, set A of students play cricket and set B of students play badminton. Write C/C++ program to find and display-
i.Set of students who play either cricket or badminton or both
ii.Set of students who play both cricket and badminton
iii.Set of students who play only cricket
iv.Set of students who play only badminton
v.Number of students who play neither cricket nor badminton
(Note- While realizing the set duplicate entries are to avoided)

Program Code:

//Assignment No:01 (Group A)
//Author: Nitin Shivale
//Title: Cricket & Badminton
#include <iostream>
using namespace std;
class game
{
    int c,b,m,i,j,k,cnt;
    int setA[10],setB[10],setC[20],setD[20],setAB[20];
    public:
    game()
    {
        c=b=m=0;
        i=j=k=0;
        cnt=0;
    }
    void getdata();
    void show();
    void uni();
    void ninor();
    void common();
    void onlycrick();
    void onlybadminton();
};
void game::getdata()
{
    cout<<"\nHow many students in SE Comp :";
    cin>>m;
    cout<<"\nEnter count of student who plays cricket:";
    cin>>c;
    for(i=0;i<c;i++)
    {
        cout<<"\nEnter the roll no:";
        cin>>setA[i];
    }
    cout<<"\nEnter count of student who plays badminton:";
    cin>>b;
    for(i=0;i<b;i++)
    {
        cout<<"\nEnter the Roll No:";
        cin>>setB[i];
    }
}
void game::uni()
{
    int flag=0;
    for(i=0;i<c;i++)
    {
        setC[k]=setA[i];
        k++;
    }
    for(j=0;j<b;j++)
    {
        for(i=0;i<c;i++)
        {
            if(setB[j]==setA[i])
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            setC[k]=setB[j];
            k++;
        }
        flag=0;
    }
    cout<<"\nThe Student who plays either Cricket or Badminton\n";
    for(i=0;i<k;i++)
    {
        cout<<"\t"<<setC[i];
    }
}

void game::common()
{
    for(i=0;i<c;i++)
    {
     setC[k]=setA[i];
     k++;
    }
    cout<<"\nThe student who plays both...\n";
    for(j=0;j<b;j++)
    {
     for(i=0;i<c;i++)
     {
      if(setB[j]==setA[i])
      {
        cout<<"\t"<<setA[i];
      }
     }
    }
}

void game::ninor()
{
    int z;
    int flag=0;
    for(i=0;i<c;i++)
    {
     setC[k]=setA[i];
     k++;
    }
    for(j=0;j<b;j++)
    {
     for(i=0;i<c;i++)
     {
      if(setB[j]==setA[i])
      {
        flag=1;
      }
     }
     if(flag==0)
     {
      setC[k]=setB[j];
      k++;
     }
     flag=0;
    }

    for(i=0;i<k;i++)
    {
        setD[cnt]=setC[i];
        cnt++;
    }
   cout<<"\n\nThe Student who plays neither Cricket nor Badminton...\n";
   flag=0;
   for(i=1;i<=m;i++)
   {
    for(j=0;j<cnt;j++)
    {
     if(setD[j]==i)
     {
      flag=1;
     }
    }
    if(flag==0)
    {
     setAB[z]=i;
     cout<<"\t"<<i;
     z++;
    }
    flag=0;
   }
}
void game::onlycrick()
{
    int flag=0;
    cout<<"\nThe student only plays Cricket...\n";
    for(i=0;i<c;i++)
    {
        for(j=0;j<b;j++)
        {
            if(setA[i]==setB[j])
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            cout<<"\t"<<setA[i];
        }
        flag=0;
    }
}

void game::onlybadminton()
{
    int flag=0;
    cout<<"\nThe student only plays Badminton...\n";
    for(j=0;j<b;j++)
    {
        for(i=0;i<c;i++)
        {
            if(setB[j]==setA[i])
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            cout<<"\t"<<setB[j];
        }
        flag=0;
    }
}
void game::show()
{
    cout<<"\nThe students who plays Cricket as follows..\n";
    for(i=0;i<c;i++)
    {
        cout<<"\t"<<setA[i];
    }
    cout<<"\nThe students who plays Badminton as follows..\n";
    for(j=0;j<b;j++)
    {
        cout<<"\t"<<setB[j];
    }
}
int main()
{
    game g;
    int ch;
   
     g.getdata();
     g.show();
     g.uni();
     g.ninor();
     g.common();
     g.onlycrick();
     g.onlybadminton();
   

    cout << "\n!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

/*****************************output ********************************************


[student@localhost DSL_LAB_M16_17]$ g++ set.cpp
[student@localhost DSL_LAB_M16_17]$ ./a.out

How many students in SE Comp :15

Enter count of student who plays cricket:5

Enter the roll no:2

Enter the roll no:4

Enter the roll no:6

Enter the roll no:7

Enter the roll no:8

Enter count of student who plays badminton:4

Enter the Roll No:3

Enter the Roll No:4

Enter the Roll No:5

Enter the Roll No:6

The students who plays Cricket as follows..
    2    4    6    7    8
The students who plays Badminton as follows..
    3    4    5    6
The Student who plays either Cricket or Badminton
    2    4    6    7    8    3    5

The Student who plays neither Cricket nor Badminton...
    1    9    10    11    12    13    14    15
The student who plays both...
    4    6
The student only plays Cricket...
    2    7    8
The student only plays Badminton...
    3    5
!!!Hello World!!!
[student@localhost DSL_LAB_M16_17]$



**********************************************************************************/
data structures and algorithms Web Developer

12 comments:

  1. plz upload simple code . 4 this Programme

    ReplyDelete
  2. plz upload simple code . 4 this Programme

    ReplyDelete
  3. Can you provide writeup for this program.

    ReplyDelete
  4. if class of se com have 10 students
    then it should only takes ip count who plays badminton or criket less than or equal to no of students in class.

    ReplyDelete
  5. The first part of function ninor() is not required(upto cout<<"\n\nStudents...).We can simply use the 'k' variable which has stored the count in uni function and execute as you did after cout statement just with some minor changes.

    ReplyDelete
  6. Plss upload code for c language

    ReplyDelete
  7. Ya Plz uplod Code for c language

    ReplyDelete
  8. As syllabus is changed please send code in pytho

    ReplyDelete
  9. I need a python code will it be possible to upload it..

    ReplyDelete