c++ program to print Average of a batsman using classes and objects.

/*write a c++ program to define a class batsman with the following information
private variable
bcode 4 digit,bname 20 char,innings,notout,bat avg(float)
which calculated(runs/(innings-notout))byfunction calc_avg
public member :
readdata() to accept values of
bcode,bname,innings,notout,runs and invoke calc_avg to calculate the avg.
display() to display
*/
#include<iostream>
using namespace std;

class Batsman{
int bcode,innings,notout,runs;
float bat_avg;
char bname[20];
float calc_avg()
    {
bat_avg =(float) runs/((float) innings -(float)notout);
return bat_avg;
}

public:
void readData();
void display();
};
void Batsman::readData(){
cout<<“Enter batsman code “;
cin>>bcode;
cout<<“Enter batsman name “;
cin>>bname;
cout<<“Enter innings “;
cin>>innings;
cout<<“Enter not outs “;
cin>>notout;
cout<<“Enter runs “;
cin>>runs;
}
void Batsman::display(){
cout<<“Batsman code “<< bcode<<endl;
cout<<“Batsman name “<< bname<<endl;
cout<<“Innings “<< innings<<endl;
cout<<“Not outs “<< notout<<endl;
cout<<“Runs “<< runs<<endl;
cout<<“Avg “<<calc_avg();
}
int main()
{
   Batsman d;
d.readData();
d.display();
return 0;
}

out:-
Enter batsman code 14
Enter batsman name bum
Enter innings 15
Enter not outs 6
Enter runs 780
Batsman code 14
Batsman name bum
Innings 15
Not outs 6
Runs 780
Avg 86.6667

Leave a Comment

Your email address will not be published. Required fields are marked *

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat