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 displayi. 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

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 displayi. 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.

#include<iostream>
using namespace std;

//---------------------------------------------------------------Global variables

int M[10],A[5],B[5],AUB[10];
int msize = 10;
int absize = 5;
int AUBsize = 0;

//---------------------------------------------------------------Input Function

void input() //To input into Arrays
OUTPUT FOR THE PROGRAM
{
   int i;

   cout<<"\n\n Enter 10 values in Set M: ";
   for(i=0; i<msize; i++) //To fill M[]
      cin>>M[i];

   cout<<"\n\n Enter 5 values in Set A: ";
   for(i=0; i<absize; i++) //To fill A[]
      cin>>A[i];

   cout<<"\n\n Enter 5 values in Set B: ";
   for(i=0; i<absize; i++) //To fill B[]
      cin>>B[i];
}

//---------------------------------------------------------------Display Function

void display() //To input into Arrays
{
   int i;

   cout<<"\n\t Set M : ";
   for(i=0; i<msize; i++) //To display M[]
      cout<<M[i]<<", ";

   cout<<"\n\t Set A : ";
   for(i=0; i<absize; i++) //To display A[]
      cout<<A[i]<<", ";

   cout<<"\n\t Set B : ";
   for(i=0; i<absize; i++) //To display B[]
      cout<<B[i]<<", ";
}

//---------------------------------------------------------------AUB Function
void AuniB()
{
   int i,j,k,flag;
   AUBsize = 0;

   for(i=0; i<absize; i++) //To fill A[] into AUB[]
   {
      AUB[AUBsize] = A[i];
      AUBsize++;
   }

   for(i=0; i<absize; i++) //To copy B[] into AUB[]
   {
       flag = 0;
       for(j=0; j<absize; j++) //To compare B[] with A[]
       {
           if(B[i] == A[j])
           {
               flag = 1;
               break;
           }
       }
       if(flag == 0)
       {
          AUB[AUBsize] = B[i];
          AUBsize++;
       }
   }

   cout<<"\n\t Set AUB : ";
   for(i=0; i<AUBsize; i++) //To display AUB[]
      cout<<AUB[i]<<", ";
}

//---------------------------------------------------------------AintB Function
void AintB()
{
   int i,j,k,flag,AintB[10];
   k = 0;

   for(i=0; i<absize; i++) //To copy B[] into AUB[]
   {
       flag = 0;
       for(j=0; j<absize; j++) //To compare B[] with A[]
       {
           if(B[i] == A[j])
           {
               flag = 1;
               break;
           }
       }
       if(flag == 1)
       {
          AintB[k] = B[i];
          k++;
       }
   }

   cout<<"\n\t Set AintB : ";
   for(i=0; i<k; i++) //To display AintB[]
      cout<<AintB[i]<<", ";
}

//...................................... AminB
void AminB()
{
   int i,j,k,flag,AminB[10];
   k = 0;

   for(i=0; i<absize; i++) //For A[]
   {
       flag = 0;
       for(j=0; j<absize; j++) //for B[]
       {
           if(A[i] == B[j])
           {
               flag = 1;
               break;
           }
       }
       if(flag == 0)
       {
          AminB[k] = A[i];
          k++;
       }
   }

   cout<<"\n\t Set AminB : ";
   for(i=0; i<k; i++) //To display AminB[]
      cout<<AminB[i]<<", ";

}

void BminA()
{
   int i,j,k,flag,BminA[10];
   k = 0;

   for(i=0; i<absize; i++) //For B[]
   {
       flag = 0;
       for(j=0; j<absize; j++) //for A[]
       {
           if(B[i] == A[j])
           {
               flag = 1;
               break;
           }
       }
       if(flag == 0)
       {
          BminA[k] = B[i];
          k++;
       }
   }

   cout<<"\n\t Set BminA : ";
   for(i=0; i<k; i++) //To display BminA[]
      cout<<BminA[i]<<", ";

}

void MminAUB()
{
   int i,j,k,flag,MminAUB[10];
   k = 0;

   for(i=0; i<msize; i++) //For M[]
   {
       flag = 0;
       for(j=0; j<AUBsize; j++) //for AUB[]
       {
           if(M[i] == AUB[j])
           {
               flag = 1;
               break;
           }
       }
       if(flag == 0) //Not matching then copy...
       {
          MminAUB[k] = M[i];
          k++;
       }
   }

   cout<<"\n\t Set M-AUB : ";
   for(i=0; i<k; i++) //To display M-AUB[]
      cout<<MminAUB[i]<<", ";

}


int main()
{
   cout<<"\n\n ***-------Set Operations-------***";
   input();
   cout<<"\n\n ***Inputs:";
   display();

   cout<<"\n\n ***Outputs:";
   AuniB();
   AintB();
   AminB();
   BminA();
   MminAUB();

   cout<<"\n\n";
   return 0;
}


For more such posts click the link:-http://svencrai.com/G8W

Comments

Popular posts from this blog

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message ?Required copies not in stock? is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

Write C++ program for storing appointment schedule for day. Appointments are booked randomly using linked list. Set start and end time and min and max duration for visit slot. Write functions for- a)Display free slots b)Book appointment c)Cancel appointment ( check validity, time bounds, availability etc) d)Sort list based on time e)Sort list based on time using pointer manipulation

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.