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;
}
马上要截止了真的是心慌慌 求助大佬帮忙