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
class Batsman{
private:
int bcode;
char bname[20];
int innings, notout, runs;
float batavg;
void calcavg(){
batavg = (float) runs / (float) (innings-notout);
}
public:
void readdata(){
std::cout << "Bcode:";
std::cin >> bcode;
std::cout << "Bname:";
std::cin >> bname;
std::cout << "Innings:";
std::cin >> innings;
std::cout << "Notout:";
std::cin >> notout;
std::cout << "Runs:";
std::cin >> runs;
calcavg();
}
void displaydata(){
std::cout << "Bcode:" << bcode << "\n";
std::cout << "Bname:" << bname << "\n";
std::cout << "Innings:" << innings << "\n";
std::cout << "Notout:" << notout << "\n";
std::cout << "Runs:" << runs << "\n";
std::cout << "Batavg:" << batavg << "\n";
}
};
Comments
Leave a comment