Answer to Question #178134 in C++ for Hari bashkar

Question #178134

Define a class Batsman with the following specifications:

Private members:

bcode 4 digits code number bname 20 characters innings, notout, runs integer type batavg it is calculated according to the formula – batavg =runs/(innings-notout) calcavg() Function to compute batavg

Public members:

readdata() Function to accept value from bcode, name, innings, notout and invoke the function calcavg(). displaydata() Function to display the data members.


1
Expert's answer
2021-04-04T11:15:24-0400
#include <iostream>

using namespace std;

class Batsman {
private:
	//bcode 4 digits code number bname 20 characters innings, notout, runs integer type batavg 
	int bcode;
	char bname[20];
	int innings,notout,runs,batavg;
	//calculated according to the formula – batavg =runs/(innings-notout) calcavg() Function to compute batavg
	void calcavg(){
		if((innings-notout)<=0){
			batavg=0;
		}
		else{
			batavg = runs/(innings-notout);
		}	
	}

public:
	//Public members:
	//readdata() Function to accept value from bcode, name, innings, notout and invoke the function calcavg().
	void readdata (){
		cout<<"Enter Batsman code: ";
		cin>> bcode;
		cout<<"Enter Batsman name: ";
		cin.ignore();
		cin.getline(bname, 20);
		cout<<"Enter innings: ";
		cin >> innings;
		cout<<"Enter notout: ";
		cin >> notout;
		cout<<"Enter runs: ";
		cin >> runs;
		calcavg();
	}
	//displaydata() Function to display the data members.
	void displaydata() {
		cout<<"\nBatsman code: "<<bcode<<"\n";
		cout<<"Batsman name: "<<bname<<"\n";
		cout<<"Innings: "<<innings<<"\n";
		cout<<"Notout: "<<notout<<"\n";
		cout<<"Runs: "<<runs<<"\n";
		cout<<"Batting Average: "<<batavg<<"\n";
	}
};


int main(){
	Batsman batsmanObject;
	batsmanObject.readdata();
	batsmanObject.displaydata();

	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS