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
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;

void readData();
void display();
void Batsman::readData(){
cout<<“Enter batsman code “;
cout<<“Enter batsman name “;
cout<<“Enter innings “;
cout<<“Enter not outs “;
cout<<“Enter 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;
return 0;

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 *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io


You have Successfully Subscribed!

Open chat