There is a class Team, that holds information about the team name, number of players in the team, and player’s code. Design the constructor function that decides the number of player in the team and initializes code for each player. Create a team and display its all data. (Implement dynamic memory allocation)
#include <iostream>
#include <string>
using namespace std;
class Team
{
string name;
int numPlys;
int* PlysCodes;
public:
Team(string _name, int _numPlys):name(_name),numPlys(_numPlys)
{
PlysCodes = new int[numPlys];
cout << "Please, enter players codes:\n";
for (int i = 0; i < numPlys; i++)
{
cout << "Player`s " << i + 1 << " code: ";
cin >> PlysCodes[i];
}
}
void Display()
{
cout << "\nInfo about team: "
<< "\nName:" << name << endl;
for (int i = 0; i < numPlys; i++)
{
cout << "Code of player " << i + 1 << ": ";
cout << PlysCodes[i] << endl;
}
}
};
int main()
{
Team a("Liverpool", 11);
a.Display();
}
Comments
Leave a comment