Answer to Question #192882 in C++ for Sankalp

Question #192882

Write necessary class and member function definitions for a cricket player object.(Use array of objects).The program should accept details from user (max 10) : player code, name, runs,Innings, played, number of times not out.The program should contain following menu:· Enter details of players.· Display average runs of a single player.Average runs of all players

1
Expert's answer
2021-05-16T12:33:33-0400
#include<iostream.h>
#include<conio.h>
class cricket
{
    private:
        int player_code;
        string name;
        int average;
        int runs;
        int innings;
        int played;
        int not_out;
    public:
        void getDetails()
        {
        cout<<“Enter the details of player: \n”;
        cout<<“player code, name, runs, innings,played, not_out \n”;
        cin>>player_code>>name>>runs>>innings>>played>>not_out;
        }
        void calculate()
        {
        average=(run/no_of_inning);
        }
        void display(int n)
        {
        cout<<"\nDetails of single plyaer: ";
        cout<<"\npcode\tname\trun\tno.Inning\tnot out\tAve.run\n";
        cout<<n<<"\t"<<name<<"\t"<<runs<<"\t"<<inning<<"\t\t"<<played<<"\t"<<not_out<<"\t"<<average;
        }
        void display()
        {
        cout<<player_codecode<<"\t"<<name<<"\t"<<run<<"\t"<<inning<<"\t"<<played<<"\t\t"<<not_out<<“\t”<<average<<endl;
        }
};
void main()
{
    int n,i,ch;
    cricket c[10];
    clrscr();
        do
        {
        cout<<“\n\tMENU:\n”;
        cout<<“\n1.Accept Detail’s\n2.Display ONE Player\n3.Display ALL Player\n4.Exit”;
        cout<<“\n\nEnter youer Choice: “;
        cin>>ch;
        switch(ch)
        {
        case 1:
        cout<<“\nHow many player information enterd: \n”;
        cin>>n;
        for(i=0;i<n;i++)
        {
        c[i].get();
        c[i].cal();
        }
        break;
        case 2:
        cout<<“\nWhich player Average run display: “;
        cout<<“\nEnter the player code: \n”;
        cin>>n;
        for(i=0;i<n;i++)
        {
        if(c[i].pcode==n)
        {
        c[i].display(n);
        }
        }
        break;
        case 3:
        cout<<“\nDetails of single plyaer: \n”;
        cout<<“\nPcode\tName\tRun\tNo.Inning\tNot out\tAve.run\n”;
        cout<<“============================================\n”;
        for(i=0;i<n;i++)
        {
        c[i].display();
        }
        break;
        case 4:
        break;
        }
        }while(ch!=4);
        getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment