有n名学生,每名学生的数据包括学号(num),姓名(name[20]),语文、数学、英语3门课的成绩(score[3])。要求在main函数中输入这n名学生的数据,然后调用一个函数count,在该函数

有没有大佬分享一下这个代码,谢谢
有n名学生,每名学生的数据包括学号(num),姓名(name[20]),语文、数学、英语3门课的成绩(score[3])。要求在main函数中输入这n名学生的数据,然后调用一个函数count,在该函数中计算出每名学生的总分(total)和平均分(ave),最后输出所有各项数据(包括原有的和新求出的)。

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 C++ 实现,包括学生信息的定义、录入、查询和统计功能: ```cpp #include <iostream> #include <string> using namespace std; const int MAX_NUM = 100; // 最大学生数 // 学生信息结构体 struct Student { string id; // 学号 string name; // 姓名 int chinese; // 语文成绩 int math; // 数学成绩 }; // 录入学生信息 void input(Student students[], int& count) { cout << "请输入学生信息(学号 姓名 语文成绩 数学成绩):" << endl; while (count < MAX_NUM) { Student s; cin >> s.id >> s.name >> s.chinese >> s.math; if (s.id == "0") { // 学号为0表示录入结束 break; } students[count++] = s; } } // 查询学生信息 void search(Student students[], int count) { string id; cout << "请输入学号查询学生信息:" << endl; cin >> id; for (int i = 0; i < count; i++) { if (students[i].id == id) { cout << "姓名:" << students[i].name << endl; cout << "语文成绩:" << students[i].chinese << endl; cout << "数学成绩:" << students[i].math << endl; return; } } cout << "未找到该学生" << endl; } // 统计学生成绩 void statistics(Student students[], int count) { int chinese_sum = 0, math_sum = 0; for (int i = 0; i < count; i++) { chinese_sum += students[i].chinese; math_sum += students[i].math; } cout << "语文总分:" << chinese_sum << endl; cout << "数学总分:" << math_sum << endl; cout << "平均语文成绩:" << static_cast<double>(chinese_sum) / count << endl; cout << "平均数学成绩:" << static_cast<double>(math_sum) / count << endl; } int main() { Student students[MAX_NUM]; int count = 0; // 学生数 int choice; // 菜单选项 do { cout << "请选择操作:" << endl; cout << "1. 录入学生信息" << endl; cout << "2. 查询学生信息" << endl; cout << "3. 统计学生成绩" << endl; cout << "0. 退出" << endl; cin >> choice; switch (choice) { case 1: input(students, count); break; case 2: search(students, count); break; case 3: statistics(students, count); break; case 0: break; default: cout << "无效选择" << endl; break; } } while (choice != 0); return 0; } ``` 在录入时,输入学号为 0 表示录入结束。在查询时,输入要查询的学号,如果找到了对应的学生,就输出该学生姓名语文成绩数学成绩;如果没有找到,就输出未找到该学生。在统计时,分别计算所有学生语文总分、数学总分和平均成绩

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值