Answer to Question #174178 in C++ for Harini.M

Question #174178

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-03-26T03:50:06-0400
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";
    }
};

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