学生成绩管理系统V2.0

news/2024/10/19 9:31:56/

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考前面章节的学生成绩管理系统V1.0”,用一维数组和函数指针作函数参数编程实现如下菜单驱动的学生成绩管理系统,其中每位同学的学号和成绩等数据可以通过不同数组的同一下标来关联:

1)录入每个学生的学号和考试成绩;

2)计算课程的总分和平均分;

3)按成绩由高到低排出名次表;

4)按成绩由低到高排出名次表;

5)按学号由小到大排出成绩表;

6)按学号查询学生排名及其考试成绩;

7)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~595个类别,统计每个类别的人数以及所占的百分比;

8)输出每个学生的学号、考试成绩。

这里只用函数指针来做函数参数。

#include <iostream>
#include <iomanip>
using namespace std;
void input(int*, float*,int*);
void caculate(float*,int*);
void sort_in_descending_order_by_score(int*, float* ,int*);
void sort_in_ascending_order_by_score(int*, float*, int*);
void sort_in_ascending_order_by_number(int* ,float* ,int*);
void search(int* ,float* ,int*);
void statistic(float* ,int *);
int main()
{int n;cout << "Input student number(n<30):";cin >> n;int choice;int xvehao[30];float score[30];int* p1 = &n, * p2 = xvehao;float *p3 = score;while (1){cout << endl;cout << "Management for Students' scores" << endl;cout << "1.Input record" << endl;cout << "2.Caculate total and average score of course" << endl;cout << "3.Sort in descending order by score" << endl;cout << "4.Sort in ascending order by score" << endl;cout << "5.Sort in ascending order by number" << endl;cout << "6.Search by number" << endl;cout << "7.Statistic analysis" << endl;cout << "8.List record" << endl;cout << "0.Exit" << endl;cout << "Please Input your choice:";cin >> choice;if (choice == 1)input(p2, p3, p1);else if (choice == 2)caculate(p3, p1);else if (choice == 3)sort_in_descending_order_by_score(p2, p3, p1);else if (choice == 4)sort_in_ascending_order_by_score(p2, p3, p1);else if (choice == 5)sort_in_ascending_order_by_number(p2, p3, p1);else if (choice == 6)search(p2, p3, p1);else if (choice == 7)statistic(p3, p1);else if (choice == 8)sort_in_ascending_order_by_number(p2, p3, p1);else if (choice == 0)break;else{cout << "Please input any number from 0 to 8!"<<endl; continue;}}return 0;
}
void input(int *p2, float *p3,int *p1)
{int i;cout << "Input student's ID, name and score:" << endl;for (i = 1; i <= *p1; i++){cin >> *(p2+i) >> *(p3+i);}}
void caculate(float *p3, int *p1)
{float sum=0,aver;int i;for (i = 1; i <= *p1; i++){sum += *(p3+i);}aver = sum / *p1;cout << "sum=" << sum << " , aver=" << fixed << setprecision(2) << aver;cout << endl;
}
void sort_in_descending_order_by_score(int *p2, float *p3, int *p1)
{int i, j,k;for (i = 1; i <= *p1; i++){k = i;for (j = i+1; j <= *p1 ; j++){if (*(p3+k) < *(p3+j))k = j;}int x = *(p2+i), y = *(p3+i);*(p2 + i) = *(p2 + k); *(p3 + i) = *(p3 + k);*(p2 + k) = x; *(p3 + k) = y;}for (i = 1; i <= *p1; i++){cout << *(p2+i) << " " << *(p3+i) << endl;}
}
void sort_in_ascending_order_by_score(int*p2, float*p3, int*p1)
{int i, j, k;for (i = 1; i <= *p1; i++){k = i;for (j = i + 1; j <= *p1; j++){if (*(p3 + k) > *(p3 + j))k = j;}int x = *(p2 + i), y = *(p3 + i);*(p2 + i) = *(p2 + k); *(p3 + i) = *(p3 + k);*(p2 + k) = x; *(p3 + k) = y;}for (i = 1; i <= *p1; i++){cout << *(p2 + i) << " " << *(p3 + i) << endl;}
}
void sort_in_ascending_order_by_number(int *p2, float *p3, int *p1)
{int i, j,k;for (i = 1; i <= *p1; i++){k = i;for (j = i + 1; j <= *p1; j++){if (*(p2+j) < *(p2+k))k = j;}int x = *(p2+i), y = *(p3+i);*(p2 + i) = *(p2 + k); *(p3 + i) = *(p3 + k);*(p2 + k) = x; *(p3 + k) = y;}for (i = 1; i <= *p1; i++){cout << *(p2 + i) << " " << *(p3 + i) << endl;}
}
void search(int *p2, float *p3, int *p1)
{int number;cin >> number;int i,k;for (i = 1; i <= *p1; i++){if (*(p2+i) == number){cout << *(p2 + i) << " " << *(p3 + i) <<endl;k = 1;break;}else k = 0;}if (k == 0)cout << "Can't find this student!"<<endl;
}
void statistic(float *p3, int *p1)
{int i;int A = 0, B = 0, C = 0, D = 0, E = 0, F = 0;for (i = 1; i <= *p1; i++){if (*(p3+i) == 100)A++;else if (*(p3 + i) >= 90 && *(p3 + i) <= 99)B++;else if (*(p3 + i) >= 80 && *(p3 + i) <= 89)C++;else if (*(p3 + i) >= 70 && *(p3 + i) <= 79)D++;else if (*(p3 + i) >= 60 && *(p3 + i) <= 69)E++;else F++;}cout << "<60 "  << F<< " " <<fixed<<setprecision(2)<< ((float)F / *p1) * 100 << "%" << endl;cout << "60-69 "  << E<< " " << fixed << setprecision(2) << ((float)E / *p1) * 100 << "%" << endl;cout << "70-79 "  << D<< " " << fixed << setprecision(2) << ((float)D / *p1) * 100 << "%" << endl;cout << "80-89 "  << C<< " " << fixed << setprecision(2) << ((float)C / *p1) *100<< "%"<<endl;cout << "90-99 "  << B<< " " << fixed << setprecision(2) << ((float)B / *p1) * 100 << "%" << endl;cout << "100 "  << A<< " " << fixed << setprecision(2) << ((float)A / *p1) * 100 << "%" << endl;
}


http://www.ppmy.cn/news/1026366.html

相关文章

netcat反弹shell

命令执行nc反弹shell 瑞士军刀 在执行命令漏洞&#xff0c;一般的利用漏洞是执行反弹shell在进行其他操作。 执行反弹shell的命令有许多。 反弹shell因为是受害者&#xff0c;反向连接远程服务器&#xff0c;请求是内部到外部&#xff0c;所以防火墙是不会进行拦截的。 反弹…

生成树协议用来解决网络风暴的问题?(第三十二课)

生成树协议用来解决网络风暴的问题?(第三十二课) 一 STP RSTP MSTP 介绍 STP(Spanning Tree Protocol)、RSTP(Rapid Spanning Tree Protocol)和MSTP(Multiple Spanning Tree Protocol)都是用于网络中避免环路的协议。 STP是最初的协议,它通过将某些端口阻塞来防止…

响应领导号召,打赢攻坚战

大周末的跑来加班&#xff0c;过来监督成员干活&#xff0c;响应领导号召&#xff0c;打赢攻坚战。 事业单位很喜欢玩攻坚&#xff0c;今年是第三次了&#xff0c;NND。预计今年还会有一两次。 平常都跟大爷一样的&#xff0c;不急不躁&#xff0c;系统上线个把月了&#xff0c…

Centos 8和Centos 7中配置阿里云的 yum 源

YUM源简介 yum是一种在Linux环境下安装、更新和删除软件包的软件管理器。通过yum&#xff0c;用户可以轻松地从软件仓库中搜索和安装包含所需软件的软件包&#xff0c;并自动处理所需的依赖关系。此外&#xff0c;yum还可以与其他软件管理工具配合使用&#xff0c;例如rpm。它…

DP1.4接口的PCB布局布线要求

DP接口即为DisplayPort接口&#xff0c;是由视频电子标准协会发布的显示接口。DP接口将在传输视频信号的同时加入对高清音频信号传输的支持&#xff0c;并且同时支持更高的分辨率以及刷新率。DP1.4通信端口规范新标准基于DP1.3规范&#xff0c;宽度不变但加入了显示压缩流技术&…

【hello C++】智能指针

目录 一、内存泄漏 1.1 什么是内存泄漏&#xff0c;内存泄漏的危害 1.2 内存泄漏分类 1.3 如何检测内存泄漏 1.4 如何避免内存泄漏 二、智能指针的使用及原理 2.1 RAII 2.2 智能指针的原理 2.3 智能指针的发展历程 2.4 智能指针的模拟及实现 三、shared_ptr 常见的问题 3.1 线程…

【微信小程序】通过调用 wx.navigateBack() 方法来退出当前界面并返回上一个界面

在点击某个按钮或执行某个条件时触发&#xff0c;示例代码&#xff1a; wx.navigateBack({delta: 1 // 返回上一个界面&#xff0c;如果要返回多个界面&#xff0c;可以增加 delta 的值 });在这个示例中&#xff0c;delta 参数指定了要返回的界面数。如果你只想返回上一个界面…

黑马项目一完结后阶段面试45题 JavaSE基础部分20题(二)

十一、集合体系结构和特点 Collection └ List 有索引&#xff0c;存取一致&#xff0c;有序&#xff0c;元素允许重复 ┃ └ ArrayLIst ┃ └ LinkedList ┃ └ Vector └ Set 无索引&#xff0c;无序&#xff0c;元素不允许重复 └ HashSet └ TreeSet └ Linke…