Click here to Skip to main content
16,016,962 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
write a class player that contains attributes for the players name,average and team.write three functions to change and display these attributes.also write a constructor that asks for input to initialize all the attributes.

What I have tried:

class player
{
private:
char name;
float avg;
char team;

public :

player()
{
name= 's';
avg = 0.05;
team = 'b';

}


void input()
{
cout << " enter a name = ";
cin >> name;


cout << " enter avg";
cin >> avg;
cout << endl;

cout << " your team ";
cin >> team;



}
void chng()
{
cout << " change a name = ";
cin >> name;
cout << endl;

cout << " changee avg";
cin >> avg;
cout << endl;

cout << " change your team ";
cin >> team;
cout << endl;

}
void display()
{


cout << " your name ";
cout << name; cout << endl;

cout << "' your avg" << avg; cout << endl;

cout << " your team " << team;
cout << endl;

}

};
void main ()

{
player p ;

p.input();
p.chng();
p.display();
system("pause");

}
Posted
Updated 8-Mar-18 15:11pm
Comments
ZurdoDev 8-Mar-18 11:49am    
Would you care to ask a question?
Member 13648231 8-Mar-18 11:56am    
yes that is my assignment which i tried but not sure whether i am doing it right.
ZurdoDev 8-Mar-18 12:01pm    
Is it doing what it is supposed to do?
Member 13648231 8-Mar-18 12:16pm    
no
Member 13648231 8-Mar-18 12:21pm    
please u tell is this code is working according to question?

Quote:
Is that solution working properly according to question?

Depends how you read the question: it asks you to:
Quote:
write three functions to change and display these attributes.
Do you have three to do that? I don't think so.

And I see no suitable constructor at all, and it specifically asks for one.

But testing it, making sure it works properly, meets the specification is part of your homework, and we don't do that for you!
 
Share this answer
 
Comments
CHill60 8-Mar-18 13:57pm    
1-vote countered. I know you don't care but I don't want newbies thinking that your answer is poor because of the one-star rating when in fact it is absolutely spot-on
Quote:
Is that solution working properly according to question?

As programmer, part of your job is to ensure that your code meet requirements and is working properly.
It is a skill you must acquire as soon as possible, it is mandatory to any serious programmer.
To know if code is working properly, about the only solution is testing the different situation your code will encounter and check is answer is correct or not.
Unit testing - Wikipedia[^]
When something go wrong, the debugger is the tool of choice to help you hunting bugs.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900