Linked list assignment - cricket badminton question

//DSA assignment 1
/* Author: Shubham Patil
    Write DSA assignment to find and display
    1: Set of students who play cricket or badminton or both
    2: Set of students who play cricket and badminton
    3: Set of students who play only cricket
    4: Set of students who play only badminton
    5: Number of students who play neither cricket nor badminton


*/
#include <iostream>
using namespace std;
const int students=10;

class Sport{

public:
    int roll;
};

int main()
{
    static int c;
    int x;
    //cout<<"Enter the number of students"<<endl;
    //int>>students;
    static int cricket[students];
    static int badminton[students];
    cout<<"Roll Numbers 1 to 10\n";
    cout<<"Enter roll numbers who play cricket,enter 0 when finished entering"<<endl;
    int i=0;
    while(c<students)
    {
        if(x!=0)
        {
            cin>>x;
            cricket[x-1]=x;
            c++;
        }
        else{
            break;
        }
    }
    cout<<"Enter roll numbers who play badminton"<<endl;
    c=0;x=1;
    while(c<students)
    {
        if(x!=0)
        {
            cin>>x;
            badminton[x-1]=x;
            c++;
        }
        else{
            break;
        }
    }
    // :> cricket or badminton both
    cout<<"Students who play cricket or badminton or both:\n"<<endl;
    for(i=0;i<10;i++)
    {
        if(cricket[i]!=0)
        {
            cout<<cricket[i]<<"\t";
        }
        else if(badminton[i]!=0)
        {
            cout<<badminton[i]<<"\t";
        }
    }

    cout<<"\nStudents who play cricket and badminton both:\n"<<endl;
    for(i=0;i<10;i++)
    {
        if(cricket[i]!=0 && badminton[i]!=0)
        {
            cout<<"\t"<<cricket[i];
        }
    }

    cout<<"\nStudents who play cricket only \n"<<endl;
    for(i=0;i<10;i++)
    {
        if(cricket[i]!=0&&cricket[i]!=badminton[i])
        {
            cout<<"\t"<<cricket[i];
        }
    }

    cout<<"\nStudents who play badminton only:\n"<<endl;
    for(i=0;i<10;i++)
    {
        if(badminton[i]!=0&&cricket[i]!=badminton[i])
        {
            cout<<"\t"<<badminton[i];
        }
    }

    cout<<"\nStudents who play neither cricket nor badminton:\n"<<endl;
    for(i=0;i<10;i++)
    {
        if(badminton[i]==0&&cricket[i]==0)
        {
            cout<<"\t"<<i+1<<"\t";
        }
    }
    return 0;
}

Post a Comment

0 Comments