Josie0625 2019-07-17 20:16 采纳率: 0%
浏览 651

小白c++代码求助 多对象输出问题

C++程序,把自己一个星期内每天走的步数记录下来,并且计算出自己一周内的最高、最低和平均步数。

请你帮云小C写一个C++程序,定义一个Step类,在类中定义7个整型变量来记录每一天的步数,一个整型变量maxStep来记录一周内的最高步数,一个整型变量minStep来记录一周内的最低步数,一个整型变量averStep来记录一周内的平均步数(若平均步数不是整数,直接向下取整)。并要求编写成员函数getMax(),getMin()和getAverage(),以及显示答案的成员函数showAnswer()等。

Input
一个数字T(T<=10),表示输入的组数,接下来T行,每行给出七个int型正整数,表示每天的步数(保证所有输出输入都为int型)。

Output
调用你所写的显示Maxstep,Minstep和Averstep的成员函数,依次给出Maxstep、Minstep和Averstep的值。

Sample Input
1
1234 3243 9894 6666 4234 2 1000

Sample Output
9894
2
3753

我的代码如下:
#include
#include

using namespace std;
class Step
{
public:
Step(int a[7]);
Step(const Step &c);
~Step(){}
int getMax();
int getMin();
float getAverage();
void showAnswer();
private:
static float Averstep;
int Maxstep,Minstep;
int step[7];
};
Step::Step(int a[7])
{
for(int i=0;i {
step[i]=a[i];
}
}
Step::Step(const Step &c)
{
for(int i=0;i {
step[i]=c.step[i];
}
}
float Step::getAverage()
{
for(int i=0;i Averstep=(Averstep+step[i])/7;
return Averstep;
}
int Step::getMax()
{
int Maxstep=step[0];
for (int i=1;i {
if (step[i]>Maxstep) {
Maxstep=step[i];
}
}
return Maxstep;
}
int Step::getMin()
{
int Minstep=step[0];
for (int i=1;i<=6;i++)
if (step[i] Minstep=step[i];
}
return Minstep;
}
void Step::showAnswer()
{
cout }
float Step::Averstep=0.0;
int main()
{
int T;
int step[7];
cin>>T;
while(cin>>step[0]>>step[1]>>step[2]>>step[3]>>step[4]>>step[5]>>step[6])
{
Step x(step);
x.showAnswer();
}
return 0;
}
马上要截止了真的是心慌慌 求助大佬帮忙

  • 写回答

2条回答 默认 最新

  • apple121694 2019-07-17 22:33
    关注

    为啥while循环里不是T呢?
    while(T)

    for(int i=0;i cin>>step[i];
    Step x(step);
    x.showAnswer();
    T--;

    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功