鱼C论坛

 找回密码
 立即注册
查看: 1731|回复: 1

c++,用using namespace std;

[复制链接]
发表于 2023-11-13 19:57:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
3)编写程序实现下列问题的求解。
<1> 在某系的成绩登记册中,每个班最多有40个学生,每份成绩表中的成绩信息包括:学号(9位字符),姓名(8位字符),成绩(百分制),备注(20位字符)。设计程序以处理一个班级的成绩信息,包括输入、输出、查询(给定分数以上或以下的学生信息)、按分数排序等。
<2> *建立一个链表,存储上题所需数据,并实现相同功能。
<3> 定义一个带参数的宏,是两个参数的值互相交换。在主函数中输入来个数作为使用宏的参数,输出交换后的两个值。(说明:在程序主函数使用宏时,只能用两个参数,如swap(a,b),不能用三个参数)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-11-13 19:57:26 | 显示全部楼层
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <list>

  5. using namespace std;

  6. struct Student {
  7.     string id;
  8.     string name;
  9.     int score;
  10.     string remark;
  11. };

  12. bool compareByScore(const Student &a, const Student &b) {
  13.     return a.score < b.score;
  14. }

  15. int main() {
  16.     list<Student> students;

  17.     // 输入学生信息
  18.     // ...

  19.     // 输出学生信息
  20.     for (const auto &student : students) {
  21.         cout << "学号:" << student.id << ",姓名:" << student.name << ",成绩:" << student.score << ",备注:" << student.remark << endl;
  22.     }

  23.     // 查询给定分数以上的学生信息
  24.     int givenScore = 80;
  25.     for (const auto &student : students) {
  26.         if (student.score >= givenScore) {
  27.             cout << "学号:" << student.id << ",姓名:" << student.name << ",成绩:" << student.score << ",备注:" << student.remark << endl;
  28.         }
  29.     }

  30.     // 按分数排序
  31.     students.sort(compareByScore);
  32.     for (const auto &student : students) {
  33.         cout << "学号:" << student.id << ",姓名:" << student.name << ",成绩:" << student.score << ",备注:" << student.remark << endl;
  34.     }

  35.     // 使用宏交换两个值
  36.     int a = 5, b = 10;
  37.     #define SWAP(x, y) { int temp = x; x = y; y = temp; }
  38.     SWAP(a, b);
  39.     cout << "a: " << a << ", b: " << b << endl;

  40.     return 0;
  41. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 07:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表