c++输入10名学生语文、数学、英语课成绩,计算每名学生的平均分并输出,分析3门课程的优秀率(高于90分即为优秀)
时间: 2023-09-20 14:05:42 浏览: 75
### 回答1:
下面是实现该功能的 C++ 代码:
```cpp
#include <iostream>
using namespace std;
int main() {
const int N = 10; // 学生数量
const int M = 3; // 课程数量
int scores[N][M]; // 存储学生成绩的二维数组
// 输入每个学生的成绩
for (int i = 0; i < N; i++) {
cout << "请输入第" << i+1 << "名学生的成绩(语文、数学、英语):";
cin >> scores[i][0] >> scores[i][1] >> scores[i][2];
}
// 计算每个学生的平均分并输出
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j < M; j++) {
sum += scores[i][j];
}
double avg = (double)sum / M;
cout << "第" << i+1 << "名学生的平均分为:" << avg << endl;
}
// 分析每门课程的优秀率
for (int j = 0; j < M; j++) {
int count = 0;
for (int i = 0; i < N; i++) {
if (scores[i][j] > 90) {
count++;
}
}
double rate = (double)count / N;
cout << "第" << j+1 << "门课程的优秀率为:" << rate << endl;
}
return 0;
}
```
该程序中使用了一个二维数组 `scores` 来存储每个学生的成绩,其中第一维表示学生的编号,第二维表示语文、数学、英语三门课程。然后使用两个嵌套的循环分别计算每个学生的平均分并输出,以及分析每门课程的优秀率。
### 回答2:
首先,我们需要输入10名学生的语文、数学、英语三门课的成绩。
接下来,我们可以通过对每个学生的三门课成绩求平均值,来计算每位学生的平均分。然后,将每位学生的平均分依次输出。
同时,我们需要统计分析三门课程的优秀率。优秀率指的是高于90分的学生人数占总学生人数的比例。
我们可以使用条件语句来判断每门课程中高于90分的学生人数,并统计出来。
最后,我们可以将每门课程的优秀率计算出来,并输出。
代码示例:
```
# 初始化总学生人数和各门课程的优秀人数
num_students = 10
excellent_chinese = 0
excellent_math = 0
excellent_english = 0
# 输入每名学生的语文、数学、英语成绩,并进行计算平均分输出
for i in range(num_students):
chinese_score = int(input("请输入第" + str(i+1) + "名学生的语文成绩:"))
math_score = int(input("请输入第" + str(i+1) + "名学生的数学成绩:"))
english_score = int(input("请输入第" + str(i+1) + "名学生的英语成绩:"))
average_score = (chinese_score + math_score + english_score) / 3
print("第" + str(i+1) + "名学生的平均分为:" + str(average_score))
# 判断每门课程的优秀学生人数
if chinese_score > 90:
excellent_chinese += 1
if math_score > 90:
excellent_math += 1
if english_score > 90:
excellent_english += 1
# 计算并输出每门课程的优秀率
excellent_rate_chinese = excellent_chinese / num_students * 100
excellent_rate_math = excellent_math / num_students * 100
excellent_rate_english = excellent_english / num_students * 100
print("语文课程的优秀率为:" + str(excellent_rate_chinese) + "%")
print("数学课程的优秀率为:" + str(excellent_rate_math) + "%")
print("英语课程的优秀率为:" + str(excellent_rate_english) + "%")
```
这样,我们就可以通过输入每名学生的成绩,计算并输出每个学生的平均分,并分析出三门课程的优秀率。
### 回答3:
假设我们已经从输入中得到了10名学生的语文、数学、英语课成绩,并存储在名为scores的数组中。接下来,我们可以通过遍历数组来计算每名学生的平均分,并统计优秀率。
首先,我们定义一个名为averages的数组来存储每名学生的平均分。然后,我们遍历scores数组,计算每名学生的平均分,并将结果存储在averages数组对应的位置上。
遍历过程中,我们还可以使用一个名为count的变量来记录优秀分数(高于90分)的学生人数。遍历scores数组的同时,每当发现某门课的成绩高于90分,就将count加1。
最后,我们可以根据优秀人数count和学生总数10,计算出3门课程的优秀率。
下面是使用Python编写的示例代码:
```python
scores = [] # 存储学生的成绩
averages = [] # 存储学生的平均分
count = 0 # 优秀分数的学生人数
# 输入学生的成绩
for i in range(10):
chinese_score = float(input("请输入第{}名学生的语文成绩:".format(i+1)))
math_score = float(input("请输入第{}名学生的数学成绩:".format(i+1)))
english_score = float(input("请输入第{}名学生的英语成绩:".format(i+1)))
scores.append([chinese_score, math_score, english_score]) # 将每个学生的成绩存储为一个列表
# 计算每名学生的平均分并统计优秀率
for score in scores:
average = sum(score) / 3 # 计算平均分
averages.append(average) # 存储平均分
if max(score) > 90: # 判断是否有成绩高于90分的
count += 1 # 计数
# 输出每名学生的平均分
for i in range(10):
print("第{}名学生的平均分为:{}".format(i+1, averages[i]))
# 输出3门课程的优秀率
chinese_excellent_rate = count / 10 * 100
math_excellent_rate = count / 10 * 100
english_excellent_rate = count / 10 * 100
print("语文课程的优秀率为:{:.2f}%".format(chinese_excellent_rate))
print("数学课程的优秀率为:{:.2f}%".format(math_excellent_rate))
print("英语课程的优秀率为:{:.2f}%".format(english_excellent_rate))
```
以上代码为一个简单的解决方案,可根据实际情况进行修改和优化。