Answer to Question #234721 in C++ for SOM

Question #234721

WAP to create the classes as per the hierarchy shown below.Include the data members in the relevant classes to store the following information:-

Name, Id, No of matches played,No. of runs scored, No. of wickets taken.

Calculate the batting average and wickets per match for an all rounder player.Use parameterized constructor to initialize the object.

[ Batting average=No. of runs scored/No. of matches played

 Wickets per match= No. Of wickets taken/ No. of matches played ]

 



1
Expert's answer
2021-09-12T18:48:54-0400
#include <iostream>


using namespace std;


class Player{
    private:
        string Name;
        int Id;
        int No_of_matches_played;
        int No_of_runs_scored;
        int No_of_wickets_taken;
    
    public:
        Player(string n,int i,int np,int nr,int nw){
            Name=n;
            Id=i;
            No_of_matches_played=np;
            No_of_runs_scored=nr;
            No_of_wickets_taken=nw;
        }
        
        void getBattingAverage(){
            int avg=No_of_runs_scored/No_of_matches_played;
            cout<<"\nThe batting average= "<<avg;
        }
        void getWicketsPerMatch(){
            int w=No_of_wickets_taken/No_of_matches_played;
            cout<<"\nWickets per match= "<<w;
        }
        
};


int main()
{
    Player p("John",123,10,30,20);
    p.getBattingAverage();
    p.getWicketsPerMatch();
    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