Answer to Question #239360 in C++ for Pranav

Question #239360

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-19T20:42:32-0400
#include <iostream>
#include <string>
using namespace std;


class Player
{
public:
	double getbatting_avg() 
	{
       batting_avg = m_run / (double)m_match;
	   return batting_avg;
	}
	double getwicket_per() 
	{
		wicket_per = m_wicket / (double)m_match;
		return wicket_per;
	}


	Player(string name, int id, int match, int run, int wicket) 
	{
		m_name= name ;
		m_id = id;
		m_match = match;
		m_run = run;
		m_wicket = wicket;
	}
	double batting_avg;
	double wicket_per;
	string m_name;
	int m_id;
	int m_match;
	int m_run;
	int m_wicket;
};


int main()
{
	// example of using an instance of a class
	Player first("John", 11111, 100, 58, 32);
	first.getbatting_avg();
	first.getwicket_per();
	cout << "Player " << first.m_name << " Batting average=" << first.getbatting_avg() << endl;
	cout << "Player " << first.m_name << " Wickets per match=" << first.getwicket_per() << endl;
}

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