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

3 Answers

+1 vote
answered May 7, 2018 by Ryan (1,230 points)
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Player
{
public:
    Player(string name, int average, string team);
    virtual ~Player();
    
    // Inputs
    void InptName();
    void InptAvg();
    void InptTeam();
private:
    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):
    m_Name(name),
    m_Average(average),
    m_Team(team)
{}

Player::~Player()
{
    /*
        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;
    
    numbers.push_back(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");
  scanf("%d",&4);
  i=1;
  while(i<=10)
{
    printf("%d*%d=%d\n",n,i,n*i);
    i=i+1;
}
}
0 votes
answered Jun 29, 2021 by Rana Ahad Nawaz (140 points)
#include <iostream>
using namespace std;
class player
{
private:
char name;
float avg;
char team;
public :
player()
{
name= 's';
avg = 6;
team = 'b';
}
void input()
{
cout << " enter a name = ";
cin >> name;
cout << " enter avg = ";
cin >> avg;
cout << " your team = ";
cin >> team;
}
void chng()
{
cout << " change a name = ";
cin >> name;
cout << " changee avg = ";
cin >> avg;
cout << " change your team = ";
cin >> team;
}
void display()
{
cout << "your name is  "<< name << endl;
cout << "your avg is " << avg << endl;
cout << "your team is now " << team << endl;
}
};
int main ()
{
player p ;
p.input();
p.chng();
p.display();
}
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.
...