2401_88458066 2025-03-22 10:47 采纳率: 0%
浏览 13

用C++编写此程序,要求简洁

在右侧编辑器中的Begin-End之间补充代码,设计 Student 类并实现用于管理学生信息表(学生表的长度不超过5)的3个函数,成员变量和函数的访问性都为公有的,具体类结构和函数要求如下:

学号,int类型

姓名,string类型

分数,float类型

带参构造函数:Student(int sid,string name,float sco),分别用这三个参数设置内部的三个成员。

void Add(int sid,string name,float sco),函数用于向学生表的末尾添加一条学生记录。

void PrintAll(),输出学生表中所有的记录,格式为:学号 姓名 成绩。

void Average(),计算学生表中学生的平均成绩并输出,格式为:平均成绩 计算结果。

提示:学生表可以用全局对象数组来完成,定义全局对象数组和定义全局变量一样,即定义在最外层作用域。

测试说明
平台会对你编写的代码进行测试,比对你输出的数值与实际正确数值,只有所有数据全部计算正确才能通过测试:

测试输入:0 厉宏富 96 1 冷欣荣 85 2 鲍俊民 76

预期输出:

0 厉宏富 96
1 冷欣荣 85
2 鲍俊民 76
平均成绩 85.6667

  • 写回答

4条回答 默认 最新

  • 道友老李 JWE233286一种基于机器视觉的水表指针读数识别及修正的方法 专利发明者 2025-03-22 10:58
    关注
    让【道友老李】来帮你解答,本回答参考gpt编写,并整理提供,如果还有疑问可以点击头像关注私信或评论。
    如果答案让您满意,请采纳、关注,非常感谢!
    ```cpp #include #include using namespace std; class Student { public: int sid; string name; float score; Student(int sid, string name, float score) { this->sid = sid; this->name = name; this->score = score; } void Add(int sid, string name, float score) { static Student students[5]; static int count = 0; students[count] = Student(sid, name, score); count++; } void PrintAll() { static Student students[5]; for(int i=0; i<5; i++) { cout << students[i].sid << " " << students[i].name << " " << students[i].score << endl; } } void Average() { static Student students[5]; float sum = 0; for(int i=0; i<5; i++) { sum += students[i].score; } cout << "平均成绩 " << sum/5 << endl; } }; int main() { Student stu; stu.Add(0, "厉宏富", 96); stu.Add(1, "冷欣荣", 85); stu.Add(2, "鲍俊民", 76); stu.PrintAll(); stu.Average(); return 0; } ```
    评论

报告相同问题?

问题事件

  • 创建了问题 3月22日