Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Need help to solve this program?

–1 vote
asked May 6, 2018 by anonymous

Write a class Player that contains attributes for the player's name, average and team. Write three functions to input, change and display these attributes. Also write constructors that ask for input to initialize all the attributes

2 Answers

0 votes
answered May 7, 2018 by Ryan (1,210 points)
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Player
    Player(string name, int average, string team);
    virtual ~Player();
    // Inputs
    void InptName();
    void InptAvg();
    void InptTeam();
    string m_Name;
    int m_Average;
    string m_Team;
    vector<int> numbers; // The numbers in the vector are averaged to create an actual average

Player::Player(string name, int average, string team):

        I didn't add any code in the destructor because I didn't find it nessecary.
        You can delete the destructor and use the default one, or add your own code.

void Player::InptName()
    string newName;
    cout << "Enter a new name for your player. ";
    cin >> newName;
    m_Name = newName;
    cout << "\n\nYour player's new name is: " << m_Name;

void Player::InptAvg()
    int number;
    cout << "Enter a number. ";
    cin >> number;
    double total;
    for (unsigned int i = 0; i < numbers.size(); i++)
        total = (total + numbers[i]);
    m_Average = (total / (numbers.size()));
    cout << "\n\n" << m_Name << "'s average is: " << m_Average;

void Player::InptTeam()
    int newTeamName;
    cout << "Enter a new name for your player's team. ";
    cin >> newTeamName;
    m_Team = newTeamName;
    cout << "\n\n" << m_Name << "'s new team name is: " << m_Team;

int main()
  // Write your code for your project here/call the member functions
0 votes
answered May 15, 2018 by anonymous
void main ()
  printf ("enter the values");
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.