Skip to main content

DSL

1: 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:

//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;
}

Comments

Popular posts from this blog

DSL

9: Program Setatement A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, and spaces are ignored. For example, ‖Poor Dan is in a droop‖ is a palindrome, as can be seen by examining the characters ―poor danisina droop‖ and observing that they are the same forward and backward. One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program with functions- 1. to check whether given string is palindrome or not that uses a stack to determine whether a string is a palindrome. 2. to remove spaces and punctuation in string, convert all the Characters to lowercase, and then call above Palindrome checking function to check for a palindrome 3. to print string in reverse order using stack Program: #include<iostream> #include<string.h> #define MAX 100 using namespace std;  struct stack ...

DSL

4: Problem Statement: Write C/C++ program for storing matrix. Write functions for  a) Check whether given matrix is upper triangular or not  b) Compute summation of diagonal elements  c) Compute transpose of matrix  d) Add, subtract and multiply two matrices #include<iostream> #include<cstdio> void Upper_Triangular(int a[10][10],int n,int m) { for(int i=0;i<n;i++){ printf("\n"); for(int j=0;j<m;j++) if(i>=j) printf(" %d ",a[i][j]); else printf(" %d ",0); } } void Addition(int a[10][10],int b[10][10],int m,int n) { int c[10][10],i,j; for(i=0;i<m;++i) { for(j=0;j<n;++j) { c[i][j]=0; c[i][j]+=a[i][j]+b[i][j]; } } printf("\nAddition Of two Matrix is : \n"); for(i=0;i<m;++i) { for(j=0;j<n;++j) { printf(" %d ",c[i][j]); } printf("\n"); } } void Dif...

OOP

6.Problem statement Develop an object oriented program in C++ to create a database of student  information system containing the following information: Name, Roll number, Class, division, Date of Birth, Blood group, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, Copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete. Program #include<iostream> #include<stdio.h> #include<cstring> using namespace std; class personal; static int count; class person {       char *name;       int *rollno,*classno;       char *bloodgroup,*div;                   public:person()              {     ...