该解决方案是否可以根据问题正常运行? [英] Is that solution working properly according to question?

查看:69
本文介绍了该解决方案是否可以根据问题正常运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个包含玩家名称,平均值和team.write三个函数的类播放器来改变和显示这些属性。还要编写一个构造函数,要求输入初始化所有属性。



我的尝试:



级玩家

{

私人:

char name;

float avg;

char team;



public:



player()

{

name ='s' ;

avg = 0.05;

team ='b';



}





无效输入()

{

cout<< 输入一个名字=;

cin>>姓名;





cout<< 输入平均值;

cin>>平均值;

cout<< endl;



cout<< 你的团队;

cin>>团队;







}

void chng()

{

cout<< 更改名称=;

cin>>姓名;

cout<< endl;



cout<< changee avg;

cin>>平均值;

cout<< endl;



cout<< 改变你的团队;

cin>>团队;

cout<<结束;



}

无效显示()

{





cout<< 你的名字;

cout<<名称; cout<< endl;



cout<< '你的平均值<<平均; cout<< endl;



cout<< 你的团队<<团队;

cout<<结束;



}



};

void main()



{

玩家p;



p.input();

p.chng();

p.display();

system(暂停);



}

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");

}

推荐答案

Quote:

是吗解决方案根据问题正常工作?

Is that solution working properly according to question?



取决于你如何阅读问题:它要求你:


Depends how you read the question: it asks you to:

引用:

编写三个函数来更改和显示这些属性。

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!


引用:

该解决方案根据问题正常运行吗?

Is that solution working properly according to question?



作为程序员,你的部分工作是确保你的代码满足要求并且工作正常。

这是一项必须尽快获得的技能,对于任何认真的程序员来说都是强制性的。

要知道代码是否正常工作正确地说,关于唯一的解决方案是测试您的代码将遇到的不同情况,并检查答案是否正确。

单元测试 - 维基百科 [ ^ ]

当出现问题时,调试器是帮助你搜寻错误的首选工具。

当你不明白你的代码在做什么或为什么它它做了什么,答案是调试器

使用调试器来查看你的代码在做什么。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


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.


这篇关于该解决方案是否可以根据问题正常运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆