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

Question #178173

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-05T07:04:19-0400
#include<iostream>

using namespace std;
class Batsman {
private:    
    int bcode;
    char bname[20];
    int innings, notout, runs;
    int batavg;
    void calcavg()     {
        if(innings!=notout)
           batavg = runs/(innings-notout);
        else
           batavg=0;
    }
public :
    void readdata();
    void displaydata();
};

void Batsman::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();
    cout<<"================================="<<endl;
}
void Batsman::displaydata() {
    cout<<"Batsman code "<<bcode<<endl
        <<"Batsman name "<<bname<<endl
        <<"Innings "<<innings<<endl
        <<"Not out "<<notout<<endl
        <<"Runs "<<runs<<endl
        <<"Batting Average "<<batavg<<endl;
}
int main() {
    Batsman myBatsman;
    myBatsman.readdata();
    myBatsman.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