Answer to Question #217355 in C++ for Fairy

Question #217355

Define a class batsman with the following specifications:Private members:bcode 4 digits code numberbname 20 charactersinnings, notout, runs integer typebatavg it is calculated according to the formula  batavg =runs/(innings-notout)calcavg() Function to compute batavgPublic members:readdata() Function to accept value from bcode, name, innings,   notout and invoke the function calcavg()displaydata() Function to display the data members on the screen.  


1
Expert's answer
2021-07-14T18:33:19-0400


#include <iostream>


using namespace std;


class batsman{
    private:
        int bcode;
        char bname[20];
        int innings, notout, runs;
        int batavg;
        int calcavg(){
           batavg =runs/(innings-notout);
           return batavg;
       }
    public:
       void readdata(){
           cout<<"\nEnter bcode: ";
           cin>>bcode;
           cout<<"\nEnter bname: ";
           cin>>bname;
           cout<<"\nEnter innings: ";
           cin>>innings;
           cout<<"\nEnter notout: ";
           cin>>notout;
           cout<<"\nEnter runs: ";
           cin>>runs;
           
           batavg=calcavg();
           
       }
       void displaydata(){
           cout<<"\nBcode: "<<bcode;
           cout<<"\nbname: "<<bname;
           cout<<"\ninnings: "<<innings;
           cout<<"\nnotout: "<<notout;
           cout<<"\nruns: "<<runs;
           cout<<"\nbatavg: "<<batavg;
       }
};
int main()
{
     batsman b;
     b.readdata();
     b.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