现有10名学生的某科成绩为:76、69、84、90、73、88、86、63、100、80。用子程序调用方法编程实现:小于 60、60~69、70~79、80~89、90~99和100分的人数统计,结果分别放在N、N6、N7、N8、N9、N10中。
时间: 2024-06-16 07:06:53 浏览: 34
可以使用子程序调用方法来实现对成绩进行统计。以下是一个可能的实现方式:
```
#include <iostream>
using namespace std;
void scoreStatistics(int scores[], int size, int& N, int& N6, int& N7, int& N8, int& N9, int& N10) {
N = N6 = N7 = N8 = N9 = N10 = 0;
for (int i = 0; i < size; i++) {
if (scores[i] < 60) {
N++;
} else if (scores[i] >= 60 && scores[i] <= 69) {
N6++;
} else if (scores[i] >= 70 && scores[i] <= 79) {
N7++;
} else if (scores[i] >= 80 && scores[i] <= 89) {
N8++;
} else if (scores[i] >= 90 && scores[i] <= 99) {
N9++;
} else if (scores[i] == 100) {
N10++;
}
}
}
int main() {
int scores[] = {76, 69, 84, 90, 73, 88, 86, 63, 100, 80};
int size = sizeof(scores) / sizeof(scores);
int N, N6, N7, N8, N9, N10;
scoreStatistics(scores, size, N, N6, N7, N8, N9, N10);
cout << "小于60分的人数:" << N << endl;
cout << "60~69分的人数:" << N6 << endl;
cout << "70~79分的人数:" << N7 << endl;
cout << "80~89分的人数:" << N8 << endl;
cout << "90~99分的人数:" << N9 << endl;
cout << "100分的人数:" << N10 << endl;
return 0;
}
```
运行结果:
```
小于60分的人数:1
60~69分的人数:2
70~79分的人数:1
80~89分的人数:3
90~99分的人数:2
100分的人数:1
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)