以下是使用 C++实现的代码: ```cpp #include <iostream> #include <string> class CPerson { public: std::string name; std::string gender; }; class CStudent : public CPerson { public: int studentId; int cLanguageScore; int cPlusPlusScore; int dataStructureScore; }; // 找到成绩最高的学生 void max(CStudent* students, int numStudents) { int maxScore = 0; int maxIndex = 0; for (int i = 0; i < numStudents; i++) { int totalScore = students[i].cLanguageScore + students[i].cPlusPlusScore + students[i].dataStructureScore; if (totalScore > maxScore) { maxScore = totalScore; maxIndex = i; } } // 输出成绩最高的学生信息 std::cout << "姓名: " << students[maxIndex].name << std::endl; std::cout << "性别: " << students[maxIndex].gender << std::endl; std::cout << "学号: " << students[maxIndex].studentId << std::endl; std::cout << "C 语言成绩: " << students[maxIndex].cLanguageScore << std::endl; std::cout << "C++成绩: " << students[maxIndex].cPlusPlusScore << std::endl; std::cout << "数据结构成绩: " << students[maxIndex].dataStructureScore << std::endl; } int main() { CStudent students[5] = { {"张三", "男", 1, 80, 90, 70}, {"李四", "女", 2, 70, 80, 90}, {"王五", "男", 3, 90, 70, 80}, {"赵六", "女", 4, 80, 70, 90}, {"孙七", "男", 5, 70, 90, 80} }; max(students, 5); return 0; } ``` 额外需要注意的逻辑点: 1. 要确保输入的学生成绩是合理的数值范围。 2. 处理可能出现多个学生成绩相同且最高的情况。 3. 考虑添加错误处理,比如学生数组为空的情况。 [2024-11-23 17:35:32 | AI写代码神器 | 574点数解答]