cs304 assignment 3 solution fall 2019 2020

cs304 assignment 3 solution fall 2019 2020

 

#include <iostream>
#include <string>
using namespace std;
class Player{
private:
string name;
string code;
int Age;
public:
Player()
{
//………….
}



void setname()
{
cout<<“\nEnter Name: “;
cin>>name;
}
void setcode()
{
cout<<” Enter PlayerCode: “;
cin>> code;
}
void setAge()
{
cout<<” Enter Age: “;
cin>> Age;
}
string getname()
{
return name;
}
string getcode()
{
return code;
}
int getAge()
{
return Age;
}
void display()
{

 



// Display function for Player Class….
}
};
class Batsman:public Player{
private:
int Inning;
int Scored;
double B_Average;
public:
Batsman()
{
//………….
}
void setInning()
{
cout<<“Enter Inning: “;
cin>>Inning;
}
void setScored()
{
cout<<“Enter Runs: “;
cin>>Scored;
}
double cal_Average()
{
return B_Average = Scored/Inning;
}
virtual void display()
{
cout<<“\nDisplaying Batsman Information:\n……………………..\n”;
cout<<“Batsman name: “<<getname()<<endl;
cout<<“Batsman code: “<<getcode()<<endl;
cout<<“Batsman age: “<<getAge()<<endl;
cout<<“Batsman Average: “<<cal_Average()<<endl;
}
};
class Bowler:public Player{
private:
int Run, Over;
double L_Average;
public:
Bowler()
{
//…….
}
void setRun()
{
cout<<“Enter Runs Conceded: “;
cin>>Run;
}
void setOver()
{
cout<<“Enter Total Overs: “;
cin>>Over;
}
double cal_Average()
{
return L_Average = Run/Over;
}
virtual void display()
{
cout<<“\nDisplaying Bowler information:\n……………………..”;
cout<<“Bowler name: “<<getname()<<endl;
cout<<“Bowler code: “<<getcode()<<endl;
cout<<“Bowler age: “<<getAge()<<endl;
cout<<“Bowler Average: “<<cal_Average()<<endl;
}
};

int main()
{
int size, i;
char arr[size], check;
Batsman batsman;
Bowler bowler;

cout<<” How many Bowlers and Batsman data you want to enter? “;
cin>>size;

while(i<size)
{
cout<<“\nEnter choice: B for batsman, L for Bowler: “<<endl;
cin>>arr[i];

if(arr[i] == ‘b’ || arr[i] == ‘B’)
{
cout<<“\nEnter following data for Batsman: “<<endl;
batsman.setname();
batsman.setcode();
batsman.setAge();
batsman.setInning();
batsman.setScored();
}
if(arr[i]==’l’ || arr[i]== ‘L’ )
{
cout<<“\nEnter following data for bowler: “<<endl;

bowler.setname();
bowler.setcode();
bowler.setAge();
bowler.setOver();
bowler.setRun();
}
cout<<“\nDo you want to enter more data (Y for yes, N for No): “;
cin>>check;

if(check==’n’ || check ==’N’ || i==size-1)
{
for (i=0; i<size; i++)
{
if(arr[i] ==’B’ || arr[i] == ‘b’)
{
batsman.display();
}
if(arr[i] == ‘L’ || arr[i] == ‘l’)
{
bowler.display();
}
}
}
i++;
}

}



 

Note:to get cpp file of this assignment please comment at the end post section.

You May Also Like

Leave a Reply

%d bloggers like this: