你可以使用一个循环语句来遍历每个学生的成绩,并找出总分最高的学生。以下是一个使用 C++ 编写的示例程序:#include <iostream>using namespace std;int main() { const int numStudents = 5; // 学生数量 float scores[numStudents][3]; // 学生成绩数组 // 输入每个学生的成绩 for (int i = 0; i < numStudents; i++) { cout << "请输入第" << i + 1 << "个学生的三门课成绩(用空格分隔):"; cin >> scores[i][0] >> scores[i][1] >> scores[i][2]; } int maxIndex = 0; // 最高总分学生的序号 float maxTotalScore = scores[0][0] + scores[0][1] + scores[0][2]; // 最高总分 // 查找最高总分学生 for (int i = 1; i < numStudents; i++) { float totalScore = scores[i][0] + scores[i][1] + scores[i][2]; if (totalScore > maxTotalScore) { maxTotalScore = totalScore; maxIndex = i; } } // 输出最高总分学生的成绩和序号 cout << "总分最高的学生的成绩为:" << scores[maxIndex][0] << " " << scores[maxIndex][1] << " " << scores[maxIndex][2] << endl; cout << "该学生的序号为:" << maxIndex + 1 << endl; return 0;}
在这个示例程序中,使用一个二维数组 `scores` 来存储每个学生的成绩。首先,通过循环语句输入每个学生的成绩。然后,使用另一个循环语句查找总分最高的学生,并记录其序号和总分。最后,输出最高总分学生的成绩和序号。
注意,在输入成绩时,要求用户按照一定格式输入每个学生的三门课成绩,用空格分隔。你也可以根据需求对输入和输出进行更改。
以上回复来自 -- ChatGPT(FishC官方接口),如未能正确解答您的问题,请继续追问。 |