1.Write a necessary class & member function definition for a cricket player object.(Use array of objects) The program should accept the details from user (max 10): Player code, name, runs, innings- played and number of times not out. The program should contain following menu: -Enter details of players. -Display average runs of a single player. -Display average runs of all players.(Use function overloading).


#include<iostream.h>
#include<conio.h>
class cricket
{
public:
float ave;
int pcode,run,no_of_inning;
int not_out;
char name[20];
public:
void get()
{
cout<<“\nEnter the details of plyaer: \n”;
cout<<“pcode name run no_of_inning not out \n”;
cin>>pcode>>name>>run>>no_of_inning>>not_out;
}
void cal()
{
ave=(run/no_of_inning);
}
void display(int n)
{
cout<<“\nDetails of single plyaer: \n”;
cout<<“\npcode\tname\trun\tno.Inning\tnot out\tAve.run\n”;
cout<<“==========================================================\n”;
cout<<n<<“\t”<<name<<“\t”<<run<<“\t”<<no_of_inning<<“\t\t”<<not_out<<“\t”<<ave;
}
void display()
{
cout<<pcode<<“\t”<<name<<“\t”<<run<<“\t”<<no_of_inning<<“\t\t”<<not_out<<“\t”<<ave<<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();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s