问题:
解答:
cpp
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<float, 3> grade;
float average=0;
for (int i = 0; i < 3; i++)
{
cout << "请输入第" << i + 1 << "次跑40米的成绩:";
cin >> grade[i];
}
for (int i = 0; i < 3; i++)
{
cout << "第" << i + 1 << "次跑40米的成绩为:"<<grade[i]<<endl;
}
cout << "测试次数为:" << grade.size() << endl;
average = (grade.at(0) + grade.at(1) + grade.at(2)) / grade.size();
cout << grade.size() << "次的平均成绩为:" << average << endl;
return 0;
}
运行结果:
考查点:
- array 数组容器\模版类
注意:
- 需要头文件
- 定义
2024年8月24日21:13:07