#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<float.h>
class cricket
{
public:int pc,run,ip,not;
public:char name[30];
void player()
{
cout<<"enter the player code:-";
cin>>pc;
cout<<"\nenter player name:-";
cin>>name;
cout<<"\nenter the runs:-";
cin>>run;
cout<<"\nentered the innings played:-";
cin>>ip;
cout<<"\nenter no. of times not out:-";
cin>>not;
}
void player(int r,int i)
{
double avg;
avg=r/(i+0.0);
cout<<"\naverage run of given player"<<avg;
}
void player(float total)
{
double avg;
avg=total/4;
cout<<"\naverage run of all players is:-"<<avg;
}
};
int main()
{
int ch,i,check;
cricket c[4];
char name[30];
float trun=0.0;
clrscr();
while(1)
{
cout<<"\n1:enter the details of player";
cout<<"\n2:average run of single player";
cout<<"\n3:average run of all players";
cout<<"\n4:exit";
cout<<"\nenter your choice:-";
cin>>ch;
switch(ch)
{
case 1:for(i=0;i<4;i++)
c[i].player();
break;
case 2:cout<<"\nenter the player name whose average run is to be calculated:-";
cin>>name;
for(i=0;i<4;i++)
{
check=strcmp(name,c[i].name);
if(check==0)
c[i].player(c[i].run,c[i].ip);
}
break;
case 3:for(i=0;i<4;i++)
trun=trun+c[i].run;
c[i].player(trun);
break;
case 4:exit(0);
}
}
getch();
return 0;
}
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<float.h>
class cricket
{
public:int pc,run,ip,not;
public:char name[30];
void player()
{
cout<<"enter the player code:-";
cin>>pc;
cout<<"\nenter player name:-";
cin>>name;
cout<<"\nenter the runs:-";
cin>>run;
cout<<"\nentered the innings played:-";
cin>>ip;
cout<<"\nenter no. of times not out:-";
cin>>not;
}
void player(int r,int i)
{
double avg;
avg=r/(i+0.0);
cout<<"\naverage run of given player"<<avg;
}
void player(float total)
{
double avg;
avg=total/4;
cout<<"\naverage run of all players is:-"<<avg;
}
};
int main()
{
int ch,i,check;
cricket c[4];
char name[30];
float trun=0.0;
clrscr();
while(1)
{
cout<<"\n1:enter the details of player";
cout<<"\n2:average run of single player";
cout<<"\n3:average run of all players";
cout<<"\n4:exit";
cout<<"\nenter your choice:-";
cin>>ch;
switch(ch)
{
case 1:for(i=0;i<4;i++)
c[i].player();
break;
case 2:cout<<"\nenter the player name whose average run is to be calculated:-";
cin>>name;
for(i=0;i<4;i++)
{
check=strcmp(name,c[i].name);
if(check==0)
c[i].player(c[i].run,c[i].ip);
}
break;
case 3:for(i=0;i<4;i++)
trun=trun+c[i].run;
c[i].player(trun);
break;
case 4:exit(0);
}
}
getch();
return 0;
}
No comments:
Post a Comment