Answer to Question #325914 in C++ for Abhishek

Question #325914

There is a Ground class that keeps the ground name and city. There is another class Game, that holds information on game names and the date of the game on which the game will be played. The Player class keeps the information about a Player, name, and code. There is a Team class that holds the team name and the total number of players counted. Using c++


1
Expert's answer
2022-04-08T07:57:51-0400
#include <iostream>
#include <string>


using namespace std;


class Ground
{
	string name; 
	string city;
public:
	Ground(string _name, string _city)
	:name(_name),city(_city){}
	void DisplayGrnd()
	{
		cout << "\nGround name is " << name
			<< "\nCity is " << city;
	}
};


class Game:public Ground
{
	string GameName;
	string GameDate;
public:
	Game(string _GameName, string _GameDate, string _name, string _city)
	:Ground(_name, _city),GameName(_GameName), GameDate(_GameDate){}
	void Display()
	{
		cout << "\nGame name is " << GameName
			<< "\nGame date is " << GameDate;
	}
};


class Player
{
	string  info;
	string  PName;
	int code;
public:
	Player(){}
	Player(string  _info, string  _PName, int _code)
	:info(_info), PName(_PName), code(_code){}
	void Display()
	{
		cout << "\nPlayer`s info is " << info
			<< "\nPlayer`s name is " << PName
			<< "\nPlayer`s code is " << code;
	}
};


class Team
{
	string TeamName;
	Player* p;
	int countPlay;
public:
	Team(string _TeamName, Player* _p, int _countPlay)
	:TeamName(_TeamName), countPlay(_countPlay)
	{
		p = new Player[countPlay];
		p = _p;
	}
	void Display()
	{
		cout << "\nTeam name is " << TeamName;
		for (int i = 0; i < countPlay; i++)
		{
			cout << "\nPlayer " << i + 1 << ":";
			p[i].Display();
		}
	}
};


int main()
{
	Game gm("Football", "05.05.2022", "York`s ground", "London");
	gm.DisplayGrnd();
	gm.Display();
	Player arr[3] = { Player("American defender","Peter",12),
					Player("English forward","Tomas",9),
					Player("French midfielder","Luke",8) };
	Team a("Chelsea",arr,3);
	a.Display();
}



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