希望可以写出完整程序参考一下,特别是数组保留下标那一部分,还有按学生学号出成绩那一块
2条回答 默认 最新
- 下坠丷 2022-06-14 18:58关注
#include<iostream> #include<string> using namespace std; void sort(int* grade, int* sno,int n); void display(int* grade,int *sno, int n); void display(int* math,int *phys,int *total, int n); int main() { cout << "输入学生人数" << endl; int n; cin >> n; int* math = new int[n]; int* phys = new int[n]; int* total = new int[n]; int* sno = new int[n]; memset(sno, 0, n); cout << "输入数学物理成绩" << endl; for (int i = 0; i < n; ++i) { cin >> math[i] >> phys[i]; total[i] = math[i] + phys[i]; } while (1) { cout << "1数学排\n" << "2物理排\n" << "3总分排\n"<<"4学号显示\n"<<"0退出\n"; int key; cin >> key; if (key == 0) { break; } switch (key) { case 1: sort(math, sno, n); display(math, sno, n); break; case 2: sort(phys, sno, n); display(phys, sno, n); break; case 3: sort(total, sno, n); display(total, sno, n); break; case 4: cout <<"学号" <<"数学" << ' ' << "物理" << ' ' << "总分" << endl; display(math, phys, total, n); default: break; } } } void sort(int* grade, int* sno,int n) { int Max; int index; int* book = new int[n]; memset(book, 0, n); for (int i = 0; i < n; ++i) { Max=-1, index = -1; for (int j = 0; j < n; ++j) { if (book[j] != 1&&grade[j]>Max) { Max = grade[j]; index = j; } } sno[i] = index; book[index] = 1; } } void display(int* grade, int* sno, int n) { for (int i = 0; i < n; i++) { cout << sno[i] << ' ' << grade[sno[i]]<<endl; } } void display(int* math, int* phys, int* total, int n) { for (int i = 0; i < n; i++) { cout <<i<<" "<< math[i] << " " << phys[i]<< " " <<total[i]<<" " << endl; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 共享文件夹会话中为什么会有WORKGROUP
- ¥15 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
- ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
- ¥15 在matlab中Application Compiler后的软件无法打开
- ¥15 想问一下STM32创建工程模板时遇到得问题
- ¥15 Fiddler抓包443
- ¥20 Qt Quick Android 项目报错及显示问题
- ¥15 而且都没有 OpenCVConfig.cmake文件我是不是需要安装opencv,如何解决?
- ¥15 oracleBIEE analytics
- ¥15 H.264选择性加密例程