用c或c++:数据结构课设--学生成绩管理系统
数据结构课设
一、问题描述
编写学生成绩管理系统,
1)要求使用线性表(顺序表或链表)实现数据存储;
2)可实现学生成绩信息的输入、修改、删除功能;
3)对数据按总分降序排序(至少采用两种排序方法实现);
4)输入一个学生姓名后,能查找到此学生的信息并输出结果(至少采用两种查找方法实现) ;
5)统计输出各门课程的平均分,最高分、最低分;
6)统计各门课程优秀、良好、中等、及格、不及格的人数及百分比。
数据结构的定义
头文件:
#include
#include<stdio.h>
#include<stdlib.h>
#include
#include
Struct student{
};//定义一个student结构体;
Status initlist(){
};//构造一个空的线性表;
Status input(){
};//输入学生信息
Status show (){
};//显示学生成绩
Status search (){
};//查找学生信息
Status alter (){
};//修改学生成绩信息
Status delet (){
};//删除学生成绩
Status insert (){
};//插入学生成绩
Status grade (){
};//统计各门课程平均分、最高分、最低分
Status people (){
};//统计各门课程优秀、良好、中等、及格、不及格的人数
Status menu(){
1、输入学生成绩 — 调用input函数();
2、显示学生成绩 —调用show函数();
3、查找学生成绩 — 调用search函数();
4、修改学生成绩 —调用alter函数();
5、删除学生成绩 —调用 delet函数();
6、插入学生成绩 —调用insert函数();
7、统计各门课程平均分、最高分、最低分
—调用grade函数();
8、统计各门课程优秀、良好、中等、及格、不及格的人数及百分比 — 调用People函数()
0、退出系统。
};//菜单
int main (){
};//主函数
程序框架
运行:前面头文件部分及结构体的定义
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<iomanip>
using namespace std;
#define ok 1
#define error 0
#define overflow -2
#define listinitsize 100 //线性表存储空间的初始分配量
#define listincrement 10 //线性表存储空间的分配增量
typedef int status;
typedef int elemtype;
struct student{
int num;
char name[8];
char class_[20];
float yuwen;
float math;
float english;
float wuli;
float shengwu;
float huaxue;
float zzhi;
float dili;
float lishi;
float sum;
};//定义一个学生的结构体
typedef struct{
student *elem; //存储空间基址
elemtype length; //当前长度
elemtype listsize; //当前分配的存储容量(以sizeof(elemtype)为单位)
}sqlist;
status initlist(sqlist &l){ //构造一个空的线性表L
l.elem = (student*)malloc(listinitsize*sizeof(student));//用student这个结构体去申请空间
if(!l.elem) return(error);
l.length = 0;
l.listsize = listinitsize;
return ok;
}
输入学生成绩:input函数
status input(sqlist &l){ //输入学生成绩
system("cls");
int i = l.length;
char sign = '0';
int flag;
cout << endl << "======>> 请输入学生成绩 <<======" << endl;
while(sign != 'n' && sign != 'N'){
loop:
cout << "学号:";
cin >> l.elem[i].num;
int j = 0;
while(j < i){
j++;
if(l.elem[i].num == l.elem[i-j].num){
cout << "您输入的学号已存在!请重新输入。" << endl;
goto loop;
}
}
cout<<"姓名:";
cin>>l.elem[i].name;
cout<<"班级:" ;
cin>>l.elem[i].class_;
do{
flag = 1;
cout << "语文成绩:" ;
cin >> l.elem[i].yuwen;
if(l.elem[i].yuwen > 100 || l.elem[i].yuwen <0){
cout << "对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 1;
cout << "数学成绩:" ;
cin >> l.elem[i].math;
if(l.elem[i].math > 100 || l.elem[i].math <0){
cout << "对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 1;
cout << "英语成绩:" ;
cin >>l.elem[i].english;
if(l.elem[i].english > 100 || l.elem[i].english <0){
cout << "对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 1;
cout << "物理成绩:" ;
cin >> l.elem[i].wuli;
if(l.elem[i].wuli > 100 || l.elem[i].wuli <0){
cout << "对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 0;
cout << "生物成绩:" ;
cin >> l.elem[i].shengwu;
if(l.elem[i].shengwu > 100 || l.elem[i].shengwu <0){
cout << "对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout << "化学成绩:" ;
cin >> l.elem[i].huaxue;
if(l.elem[i].huaxue > 100 || l.elem[i].huaxue <0){
cout << "对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout << "政治成绩:" ;
cin >> l.elem[i].zzhi;
if(l.elem[i].zzhi > 100 || l.elem[i].zzhi <0){
cout << "对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout << "地理成绩:" ;
cin >> l.elem[i].dili;
if(l.elem[i].dili > 100 || l.elem[i].dili <0){
cout << "对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout << "历史成绩:" ;
cin >> l.elem[i].lishi;
if(l.elem[i].lishi > 100 || l.elem[i].lishi <0){
cout << "对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
l.elem[i].sum = (l.elem[i].yuwen + l.elem[i].math + l.elem[i].english +
l.elem[i].wuli + l.elem[i].shengwu + l.elem[i].huaxue + l.elem[i].zzhi + l.elem[i].dili + l.elem[i].lishi);
cout << "总分为:" << l.elem[i].sum << endl;
cout << "======>> 提示:是否继续输入学生成绩?(y/n)";
cin >> sign;
i++;
l.length++;
}
return ok;
}
显示学生成绩:show(快排、冒泡)
status show(sqlist l){ //显示学生成绩(快排)
float s;
char t[20];
int i,k,j,n,m;
for(i=0;i<l.length-1;i++){ //n个数据需进行n-1趟比较
k=i; //先使k记录排序范围内的第一个元素的位置
for(j=i+1;j<l.length;j++) //找出最大元素,有k记录
if(l.elem[j].sum>l.elem[k].sum)
k=j;
if(k!=i){ //如果排序范围的第一个元素(即第i个元素不是最大值)
n=l.elem[k].sum; //则将最大元素与第i个元素对调
l.elem[k].sum=l.elem[i].sum;
l.elem[i].sum=n;
//交换课程
strcpy(t, l.elem[k].class_);
strcpy(l.elem[k].class_, l.elem[i].class_);
strcpy(l.elem[i].class_,t);
//num
m= l.elem[k].num;
l.elem[k].num = l.elem[i].num;
l.elem[i].num = m;
//name
strcpy(t, l.elem[k].name);
strcpy(l.elem[k].name, l.elem[i].name);
strcpy(l.elem[i].name, t);
//yuwen
s = l.elem[k].yuwen;
l.elem[k].yuwen= l.elem[i].yuwen;
l.elem[i].yuwen = s;
//math
s = l.elem[k].math;
l.elem[k].math = l.elem[i].math;
l.elem[i].math = s;
//english
s = l.elem[k].english;
l.elem[k].english = l.elem[i].english;
l.elem[i].english = s;
//wuli
s = l.elem[k].wuli;
l.elem[k].wuli = l.elem[i].wuli;
l.elem[i].wuli = s;
//shengwu
s = l.elem[k].shengwu;
l.elem[k].shengwu = l.elem[i].shengwu;
l.elem[i].shengwu= s;
//huaxue
s = l.elem[k].huaxue;
l.elem[k].huaxue = l.elem[i].huaxue;
l.elem[i].huaxue = s;
//zzhi
s = l.elem[k].zzhi;
l.elem[k].zzhi = l.elem[i].zzhi;
l.elem[i].zzhi = s;
//dili
s = l.elem[k].dili;
l.elem[k].dili = l.elem[i].dili;
l.elem[i].dili = s;
//lishi
s = l.elem[k].lishi;
l.elem[k].lishi = l.elem[i].lishi;
l.elem[i].lishi= s;
}
}
cout << "-----------------------------------------------------------------------------------------------------------------------" << endl;
cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
<< "语文" << "\t" << "数学" << "\t" << "英语" << "\t"
<< "物理" << "\t" << "生物" << "\t" << "化学" << "\t"
<< "政治" << "\t" << "地理" << "\t" << "历史" << "\t"
<< "总分" << "\t" <<endl;
cout << "-----------------------------------------------------------------------------------------------------------------------" << endl;
for (int i = 0; i < l.length; i++) {
cout << l.elem[i].class_ << "\t" << l.elem[i].num << "\t" << l.elem[i].name << "\t"
<< l.elem[i].yuwen << "\t" << l.elem[i].math << "\t" << l.elem[i].english << "\t"
<< l.elem[i].wuli << "\t" << l.elem[i].shengwu << "\t" << l.elem[i].huaxue << "\t"
<< l.elem[i].zzhi << "\t" << l.elem[i].dili << "\t" << l.elem[i].lishi << "\t"
<< l.elem[i].sum << "\t" << endl;
}
return ok;
}
也有第二种冒泡排序:
status show(sqlist l) { //显示学生成绩(冒泡排序)
system("cls");
int i, j, k;
float s;
char t[20];
cout << endl << "======>> 降序排列 <<======" << endl;
int n = l.length;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (l.elem[j].sum< l.elem[j + 1].sum) {
//交换课程
strcpy(t, l.elem[j + 1].class_);
strcpy(l.elem[j + 1].class_, l.elem[j].class_);
strcpy(l.elem[j].class_,t);
//num
k = l.elem[j + 1].num;
l.elem[j + 1].num = l.elem[j].num;
l.elem[j].num = k;
//name
strcpy(t, l.elem[j + 1].name);
strcpy(l.elem[j + 1].name, l.elem[j].name);
strcpy(l.elem[j].name, t);
//
s = l.elem[j + 1].yuwen;
l.elem[j + 1].yuwen= l.elem[j].yuwen;
l.elem[j].yuwen = s;
//math
s = l.elem[j + 1].math;
l.elem[j + 1].math = l.elem[j].math;
l.elem[j].math = s;
//english
s = l.elem[j + 1].english;
l.elem[j + 1].english = l.elem[j].english;
l.elem[j].english = s;
//wuli
s = l.elem[j + 1].wuli;
l.elem[j + 1].wuli = l.elem[j].wuli;
l.elem[j].wuli = s;
//shengwu
s = l.elem[j + 1].shengwu;
l.elem[j + 1].shengwu = l.elem[j].shengwu;
l.elem[j].shengwu= s;
//huaxue
s = l.elem[j + 1].huaxue;
l.elem[j + 1].huaxue = l.elem[j].huaxue;
l.elem[j].huaxue = s;
//zzhi
s = l.elem[j + 1].zzhi;
l.elem[j + 1].zzhi = l.elem[j].zzhi;
l.elem[j].zzhi = s;
//dili
s = l.elem[j + 1].dili;
l.elem[j + 1].dili = l.elem[j].dili;
l.elem[j].dili = s;
//lishi
s = l.elem[j + 1].lishi;
l.elem[j + 1].lishi = l.elem[j].lishi;
l.elem[j].lishi= s;
//sum
s = l.elem[j + 1].sum;
l.elem[j + 1].sum= l.elem[j].sum;
l.elem[j].sum= s;
}
}
}
cout << "-----------------------------------------------------------------------------------------------------------------------" << endl;
cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
<< "语文" << "\t" << "数学" << "\t" << "英语" << "\t"
<< "物理" << "\t" << "生物" << "\t" << "化学" << "\t"
<< "政治" << "\t" << "地理" << "\t" << "历史" << "\t"
<< "总分" << "\t" <<endl;
cout << "-----------------------------------------------------------------------------------------------------------------------" << endl;
for (int i = 0; i < n; i++) {
cout << l.elem[i].class_ << "\t" << l.elem[i].num << "\t" << l.elem[i].name << "\t"
<< l.elem[i].yuwen << "\t" << l.elem[i].math << "\t" << l.elem[i].english << "\t"
<< l.elem[i].wuli << "\t" << l.elem[i].shengwu << "\t" << l.elem[i].huaxue << "\t"
<< l.elem[i].zzhi << "\t" << l.elem[i].dili << "\t" << l.elem[i].lishi << "\t"
<< l.elem[i].sum << "\t" << endl;
}
}
查找学生成绩:search函数(顺序查找、折半查找)
顺序查找代码如下:
status search(sqlist l) //查找学生成绩(顺序查找 )
{
system("cls");
int i=0;
int n=l.length;
char s[20];
cout<<"请输入要查找的学生成绩的姓名:";
cin>>s;
for(i=0;i<n;i++)
{
if(i<n&&strcmp(l.elem[i].name,s)==0)
{
cout << "----------------------------" << endl;
cout << "班级:" << l.elem[i].class_ << endl;
cout << "学号:" << l.elem[i].num << endl;
cout << "姓名:" << l.elem[i].name << endl;
cout << "语文:" << l.elem[i].yuwen << endl;
cout << "数学:" << l.elem[i].math << endl;
cout << "英语:" << l.elem[i].english << endl;
cout << "物理:" << l.elem[i].wuli << endl;
cout << "生物:" << l.elem[i].shengwu << endl;
cout << "化学:" << l.elem[i].huaxue << endl;
cout << "政治:" << l.elem[i].zzhi << endl;
cout << "地理:" << l.elem[i].dili << endl;
cout << "历史:" << l.elem[i].lishi<< endl;
cout << "总分:" << l.elem[i].sum<< endl;
break;
}
}
if(i==n)
cout << "======>> 对不起,无法找到该学生...... <<======" << endl;
return ok;
}
折半查找代码如下:
status search(sqlist l) //查找学生成绩(折半查找)
{
system("cls");
char k[20];
cout<<"请输入要查找的学生成绩的姓名:" ;
cin>>k;
int i,j,m,n;
float s;
char t[20]={0};
n = l.length;
for(i=0;i<n-1;i++){
for(j=0;j<n-i-1;j++){
if(strcmp(l.elem[j].name,l.elem[j+1].name)<0){
//name
strcpy(t,l.elem[j].name);
strcpy(l.elem[j].name,l.elem[j+1].name);
strcpy(l.elem[j+1].name,t);
// class
strcpy(t, l.elem[j].class_);
strcpy(l.elem[j].class_, l.elem[j+1].class_);
strcpy(l.elem[j+1].class_,t);
//num
m = l.elem[j].num;
l.elem[j].num = l.elem[j+1].num;
l.elem[j+1].num = m;
//yuwen
s = l.elem[j].yuwen;
l.elem[j].yuwen= l.elem[j+1].yuwen;
l.elem[j+1].yuwen = s;
//math
s = l.elem[j].math;
l.elem[j].math = l.elem[j+1].math;
l.elem[j+1].math = s;
//english
s = l.elem[j].english;
l.elem[j].english = l.elem[j+1].english;
l.elem[j+1].english = s;
//wuli
s = l.elem[j].wuli;
l.elem[j].wuli = l.elem[j+1].wuli;
l.elem[j+1].wuli = s;
//shengwu
s = l.elem[j].shengwu;
l.elem[j].shengwu = l.elem[j+1].shengwu;
l.elem[j+1].shengwu= s;
//huaxue
s = l.elem[j].huaxue;
l.elem[j].huaxue = l.elem[j+1].huaxue;
l.elem[j+1].huaxue = s;
//zzhi
s = l.elem[j].zzhi;
l.elem[j].zzhi = l.elem[j+1].zzhi;
l.elem[j+1].zzhi = s;
//dili
s = l.elem[j].dili;
l.elem[j].dili = l.elem[j+1].dili;
l.elem[j+1].dili = s;
//lishi
s = l.elem[j].lishi;
l.elem[j].lishi = l.elem[j+1].lishi;
l.elem[j+1].lishi= s;
}
}
}
int low,high,mid;
low = 0;
high = l.length-1;
while(low<=high)
{
mid=(low+high)/2;
if(strcmp(k,l.elem[mid].name) == 0){
cout << "----------------------------" << endl;
cout << "班级:" << l.elem[mid].class_ << endl;
cout << "学号:" << l.elem[mid].num << endl;
cout << "姓名:" << l.elem[mid].name << endl;
cout << "语文:" << l.elem[mid].yuwen << endl;
cout << "数学:" << l.elem[mid].math << endl;
cout << "英语:" << l.elem[mid].english << endl;
cout << "物理:" << l.elem[mid].wuli << endl;
cout << "生物:" << l.elem[mid].shengwu << endl;
cout << "化学:" << l.elem[mid].huaxue << endl;
cout << "政治:" << l.elem[mid].zzhi << endl;
cout << "地理:" << l.elem[mid].dili << endl;
cout << "历史:" << l.elem[mid].lishi<< endl;
cout << "总分:" << l.elem[mid].sum<< endl;
return ok;
}
else if(strcmp(k,l.elem[mid].name) > 0)
high=mid-1;
else
low=mid+1;
}
cout << "======>> 对不起,无法找到该学生...... <<======" << endl;
return ok;
}
修改学生成绩:alter函数
status alter(sqlist &l) { //修改学生成绩
system("cls");
int n = l.length;
int s,flag;
int i = 0;
cout << endl << "======>> 修改学生成绩 <<======" << endl;
cout << "请输入要修改成绩学生的学号:";
cin >> s;
while ((l.elem[i].num - s) != 0 && i < n)i++;
if (i == n) {
cout << "======>> 对不起,无法找到该学生...... <<======" << endl;
}
else {
cout << "----------------------------------------------------------------------------------------------------" << endl;
cout << "班级" << "\t" << "学号" << "\t" << "姓名" << "\t"
<< "语文" << "\t" << "数学" << "\t" << "英语" << "\t"
<< "物理" << "\t" << "生物" << "\t" << "化学" << "\t"
<< "政治" << "\t" << "地理" << "\t"<< "历史" << "\t"
<< "总分" << "\t"<<endl;
cout << "----------------------------------------------------------------------------------------------------" << endl;
cout << l.elem[i].class_<< "\t" << l.elem[i].num << "\t" << l.elem[i].name << "\t"
<< l.elem[i].yuwen << "\t" << l.elem[i].math << "\t" << l.elem[i].english << "\t"
<< l.elem[i].wuli << "\t" << l.elem[i].shengwu << "\t" << l.elem[i].huaxue << "\t"
<< l.elem[i].zzhi << "\t" << l.elem[i].dili << "\t" << l.elem[i].lishi << "\t"
<< l.elem[i].sum << "\t" << endl;
cout << endl << "请重新输入该学生成绩: " << endl;
do{
flag = 1;
cout<< "语文成绩:" ;
cin>>l.elem[i].yuwen;
if(l.elem[i].yuwen > 100 || l.elem[i].yuwen <0){
cout<<"对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 1;
cout<< "数学成绩:" ;
cin>>l.elem[i].math;
if(l.elem[i].math > 100 || l.elem[i].math <0){
cout<<"对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 1;
cout<< "英语成绩:" ;
cin>>l.elem[i].english;
if(l.elem[i].english > 100 || l.elem[i].english <0){
cout<<"对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 1;
cout<< "物理成绩:" ;
cin>>l.elem[i].wuli;
if(l.elem[i].wuli > 100 || l.elem[i].wuli <0){
cout<<"对不起,请输入1-100之间的数字!\n" ;
}
else{
flag = 0;
}
}while(flag);
do{
flag = 0;
cout<< "生物成绩:" ;
cin>>l.elem[i].shengwu;
if(l.elem[i].shengwu > 100 || l.elem[i].shengwu <0){
cout<<"对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout<< "化学成绩:" ;
cin>>l.elem[i].huaxue;
if(l.elem[i].huaxue > 100 || l.elem[i].huaxue <0){
cout<<"对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout<< "政治成绩:" ;
cin>>l.elem[i].zzhi;
if(l.elem[i].zzhi > 100 || l.elem[i].zzhi <0){
cout<<"对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout<< "地理成绩:" ;
cin>>l.elem[i].dili;
if(l.elem[i].dili > 100 || l.elem[i].dili <0){
cout<<"对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
do{
flag = 0;
cout<< "历史成绩:" ;
cin>>l.elem[i].lishi;
if(l.elem[i].lishi > 100 || l.elem[i].lishi <0){
cout<<"对不起,请输入1-100之间的数字!\n";
}
else{
flag = 1;
}
}while(flag == 0);
l.elem[i].sum = (l.elem[i].yuwen + l.elem[i].math + l.elem[i].english +
l.elem[i].wuli + l.elem[i].shengwu + l.elem[i].huaxue + l.elem[i].zzhi+ l.elem[i].dili+ l.elem[i].lishi) ;
cout << "总分:" << l.elem[i].sum << endl;
/* l.elem[i].average = (l.elem[i].yuwen + l.elem[i].math + l.elem[i].english +
l.elem[i].wuli + l.elem[i].shengwu + l.elem[i].huaxue + l.elem[i].zzhi+ l.elem[i].dili+ l.elem[i].lishi) / 9;
cout << "平均分:" << l.elem[i].average << endl;*/
}
return ok;
}
删除学生成绩:delete函数
status delet(sqlist &l) { //删除学生成绩
system("cls");
int n = l.length;
int s;
int i = 0, j ;
cout << endl << "======>> 删除学生成绩 <<======" << endl;
cout << "请输入要删除的学生的学号:";
cin >> s;
while ((l.elem[i].num - s) != 0 && i < n)i++;
if (i == n) {
cout << "======>> 对不起,无法找到该学生...... <<======" << endl;
}
else {
for (j = i; j < n - 1; j++) {
strcpy(l.elem[j].class_,l.elem[j + 1].class_);
l.elem[j].num = l.elem[j + 1].num;
strcpy(l.elem[j].name, l.elem[j + 1].name);
l.elem[j].yuwen = l.elem[j + 1].yuwen;
l.elem[j].math = l.elem[j + 1].math;
l.elem[j].english = l.elem[j + 1].english;
l.elem[j].wuli = l.elem[j + 1].wuli;
l.elem[j].shengwu = l.elem[j + 1].shengwu;
l.elem[j].huaxue = l.elem[j + 1].huaxue;
l.elem[j].zzhi = l.elem[j + 1].zzhi;
l.elem[j].dili = l.elem[j + 1].dili;
l.elem[j].lishi = l.elem[j + 1].lishi;
l.elem[j].sum = l.elem[j + 1].sum;
}
cout << "======>> 提示:已成功删除!" << endl;
l.length--;
}
return ok;
}
插入学生的成绩:insert函数
status delet(sqlist &l) { //删除学生成绩
system("cls");
int n = l.length;
int s;
int i = 0, j ;
cout << endl << "======>> 删除学生成绩 <<======" << endl;
cout << "请输入要删除的学生的学号:";
cin >> s;
while ((l.elem[i].num - s) != 0 && i < n)i++;
if (i == n) {
cout << "======>> 对不起,无法找到该学生...... <<======" << endl;
}
else {
for (j = i; j < n - 1; j++) {
strcpy(l.elem[j].class_,l.elem[j + 1].class_);
l.elem[j].num = l.elem[j + 1].num;
strcpy(l.elem[j].name, l.elem[j + 1].name);
l.elem[j].yuwen = l.elem[j + 1].yuwen;
l.elem[j].math = l.elem[j + 1].math;
l.elem[j].english = l.elem[j + 1].english;
l.elem[j].wuli = l.elem[j + 1].wuli;
l.elem[j].shengwu = l.elem[j + 1].shengwu;
l.elem[j].huaxue = l.elem[j + 1].huaxue;
l.elem[j].zzhi = l.elem[j + 1].zzhi;
l.elem[j].dili = l.elem[j + 1].dili;
l.elem[j].lishi = l.elem[j + 1].lishi;
l.elem[j].sum = l.elem[j + 1].sum;
}
cout << "======>> 提示:已成功删除!" << endl;
l.length--;
}
return ok;
}
status insert(sqlist &l) { //插入学生成绩
system("cls");
int n = l.length;
char s='0';
cout << endl << "=======>> 增加学生成绩 <<========" << endl;
while (s != 'n' && s != 'N') {
cout << "班级:";
cin >> l.elem[n].class_;
loop:
cout<<"学号:";
cin>>l.elem[n].num;
int j = 0;
while(j < n){
j++;
if(l.elem[n].num==l.elem[n-j].num){
cout<<"您输入的学号已存在!请重新输入。"<<endl;
goto loop;
}
}
cout << "姓名:";
cin >> l.elem[n].name;
cout << "语文:";
cin >> l.elem[n].yuwen;
cout << "数学:";
cin >> l.elem[n].math;
cout << "英语:";
cin >> l.elem[n].english;
cout << "物理:";
cin >> l.elem[n].wuli;
cout << "生物:";
cin >> l.elem[n].shengwu;
cout << "化学:";
cin >> l.elem[n].huaxue;
cout << "政治:";
cin >> l.elem[n].zzhi;
cout << "地理:";
cin >> l.elem[n].dili;
cout << "历史:";
cin >> l.elem[n].lishi;
l.elem[n].sum = (l.elem[n].yuwen + l.elem[n].math + l.elem[n].english +
l.elem[n].wuli + l.elem[n].shengwu + l.elem[n].huaxue + l.elem[n].zzhi+ l.elem[n].dili+ l.elem[n].lishi) ;
cout << "总分:" << l.elem[n].sum << endl;
n++;
l.length++;
cout << "======>> 是否继续插入(y/n)";
cin >> s;
}
return ok;
}
统计各门课程平均分、最高分、最低分
status grade(sqlist l){ //统计各门课程平均分、最高分、最低分
system("cls");
int i;
int a_sum = 0;
int max,min;
int n = l.length;
cout << "-----------------------------------------------------------------------------------------------------------------------" << endl;
cout << " " << "\t" << "平均分" << "\t" << "\t" << "最高分" << "\t" << "最低分" << "\t" << endl;
cout << "-----------------------------------------------------------------------------------------------------------------------" << endl;
//语文
max = l.elem[0].yuwen;
min = l.elem[0].yuwen;
for(i = 0;i < n;i++){
a_sum += l.elem[i].yuwen;
if(l.elem[i].yuwen > max)
max = l.elem[i].yuwen;
if(l.elem[i].yuwen < min)
min = l.elem[i].yuwen;
}
cout<< "语文" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//数学
a_sum = 0;
max = l.elem[0].math;
min = l.elem[0].math;
for(i = 0;i < n;i++){
a_sum += l.elem[i].math;
if(l.elem[i].math > max)
max = l.elem[i].math;
if(l.elem[i].math < min)
min = l.elem[i].math;
}
cout<< "数学" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//英语
a_sum = 0;
max = l.elem[0].english;
min = l.elem[0].english;
for(i = 0;i < n;i++){
a_sum += l.elem[i].english;
if(l.elem[i].english > max)
max = l.elem[i].english;
if(l.elem[i].english < min)
min = l.elem[i].english;
}
cout<< "英语" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//物理
a_sum = 0;
max = l.elem[0].wuli;
min = l.elem[0].wuli;
for(i = 0;i < n;i++){
a_sum += l.elem[i].wuli;
if(l.elem[i].wuli > max)
max = l.elem[i].wuli;
if(l.elem[i].wuli < min)
min = l.elem[i].wuli;
}
cout<< "物理" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//生物
a_sum = 0;
max = l.elem[0].shengwu;
min = l.elem[0].shengwu;
for(i = 0;i < n;i++){
a_sum += l.elem[i].shengwu;
if(l.elem[i].shengwu > max)
max = l.elem[i].shengwu;
if(l.elem[i].shengwu < min)
min = l.elem[i].shengwu;
}
cout<< "生物" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//化学
a_sum = 0;
max = l.elem[0].huaxue;
min = l.elem[0].huaxue;
for(i = 0;i < n;i++){
a_sum += l.elem[i].huaxue;
if(l.elem[i].huaxue > max)
max = l.elem[i].huaxue;
if(l.elem[i].huaxue < min)
min = l.elem[i].huaxue;
}
cout<< "化学" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//政治
a_sum = 0;
max = l.elem[0].zzhi;
min = l.elem[0].zzhi;
for(i = 0;i < n;i++){
a_sum += l.elem[i].zzhi;
if(l.elem[i].zzhi > max)
max = l.elem[i].zzhi;
if(l.elem[i].zzhi < min)
min = l.elem[i].zzhi;
}
cout<< "政治" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//地理
a_sum = 0;
max = l.elem[0].dili;
min = l.elem[0].dili;
for(i = 0;i < n;i++){
a_sum += l.elem[i].dili;
if(l.elem[i].dili > max)
max = l.elem[i].dili;
if(l.elem[i].dili < min)
min = l.elem[i].dili;
}
cout<< "地理" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
//历史
a_sum = 0;
max = l.elem[0].lishi;
min = l.elem[0].lishi;
for(i = 0;i < n;i++){
a_sum += l.elem[i].lishi;
if(l.elem[i].lishi > max)
max = l.elem[i].lishi;
if(l.elem[i].lishi < min)
min = l.elem[i].lishi;
}
cout<< "历史" << "\t" << (float) a_sum/l.length << "\t" << "\t" << max << "\t" << min <<endl;
return ok;
}
统计各门课程优秀、良好、中等、及格、不及格的人数及百分比
status people(sqlist l) //统计各门课程优秀、良好、中等、及格、不及格的人数及百分比
{
system("cls");
//int yxiu,lhao,zdeng,jge,bjge;
int a=0,b=0,c=0,d=0,e=0;
float aa,bb,cc,dd,ee;
int n=l.length;
cout << "-------------------------------------------------------------------------------------------" << endl;
cout <<"课程名 "<<"\t" <<"优秀 " <<"\t" <<"\t"<<"良好 "<<"\t"<<"\t"<<"中等 "<<"\t" <<"\t"<<"及格 "<<"\t"<<"\t"<<"不及格 "<<endl;
//语文
for (int i=0;i<n;i++)
{ if(l.elem[i].yuwen<=100&&l.elem[i].yuwen>=90){ a++;} //优秀
else if(l.elem[i].yuwen>=80){
b++;} //良好
else if (l.elem[i].yuwen>=70){
c++; }//中等
else if (l.elem[i].yuwen>=60){
d++; } //及格
else if(l.elem[i].yuwen<60){
e++;} //不及格
}
aa=(float((float)a/(float)l.length)*100);
bb=(float((float)b/(float)l.length)*100);
cc=(float((float)c/(float)l.length)*100);
dd=(float((float)d/(float)l.length)*100);
ee=(float((float)e/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "语文 "<< "\t" << "\t" << a << "/" << (float)aa << "%" << "\t"<<"\t" << b << "/" << (float)bb << "%" << "\t"<<"\t"
<< c << "/" << (float)cc << "%" << "\t" <<"\t"<< d << "/" << (float)dd << "%" << "\t"<<"\t"
<< e << "/" << (float)ee << "%" << "\t" <<"\t"<< endl;
//数学
int a1=0,b1=0,c1=0,d1=0,e1=0;
float aa1,bb1,cc1,dd1,ee1;
for (int i=0;i<n;i++)
{
if(l.elem[i].math<=100&&l.elem[i].math>=90){
a1++;} //优秀
else if
(l.elem[i].math>=80){
b1++;}//良好
else if (l.elem[i].math>=70){
c1++;}//中等
else if (l.elem[i].math>=60){
d1++;}//及格
else if(l.elem[i].math<60){
e1++;} //不及格
}
aa1=(float((float)a1/(float)l.length)*100);
bb1=(float((float)b1/(float)l.length)*100);
cc1=(float((float)c1/(float)l.length)*100);
dd1=(float((float)d1/(float)l.length)*100);
ee1=(float((float)e1/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "数学 "<< "\t" << "\t" << a1 << "/" << (float)aa1 << "%" << "\t" <<"\t"<< b1 << "/" << (float)bb1 << "%" << "\t"<<"\t"
<< c1 << "/" << (float)cc1 << "%" << "\t"<<"\t" << d1 << "/" << (float)dd1 << "%" << "\t" <<"\t"
<< e1 << "/" << (float)ee1 << "%" << "\t"<<"\t" << endl;
//英语
int a2=0,b2=0,c2=0,d2=0,e2=0;
float aa2,bb2,cc2,dd2,ee2;
for (int i=0;i<n;i++)
{
if(l.elem[i].english<=100&&l.elem[i].english>=90){
a2++;} //优秀
else if(l.elem[i].english>=80){
b2++;} //良好
else if (l.elem[i].english>=70){
c2++; } //中等
else if (l.elem[i].english>=60){
d2++;}//及格
else if(l.elem[i].english<60){
e2++;} //不及格
}
aa2=(float((float)a2/(float)l.length)*100);
bb2=(float((float)b2/(float)l.length)*100);
cc2=(float((float)c2/(float)l.length)*100);
dd2=(float((float)d2/(float)l.length)*100);
ee2=(float((float)e2/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "英语 "<< "\t" << "\t" << a2 << "/" << (float)aa2 << "%" << "\t"<<"\t" << b2 << "/" << (float)bb2 << "%" << "\t"<<"\t"
<< c2 << "/" << (float)cc2 << "%" << "\t" <<"\t"<< d2 << "/" << (float)dd2 << "%" << "\t"<<"\t"
<< e2 << "/" << (float)ee2 << "%" << "\t"<<"\t" << endl;
//物理
int a3=0,b3=0,c3=0,d3=0,e3=0;
float aa3,bb3,cc3,dd3,ee3;
for (int i=0;i<n;i++)
{
if(l.elem[i].wuli<=100&&l.elem[i].wuli>=90){
a3++;} //优秀
else if(l.elem[i].wuli>=80){
b3++;}//良好
else if (l.elem[i].wuli>=70){
c3++; } //中等
else if (l.elem[i].wuli>=60){
d3++;}//及格
else if(l.elem[i].wuli<60){
e3++;} //不及格
}
aa3=(float((float)a3/(float)l.length)*100);
bb3=(float((float)b3/(float)l.length)*100);
cc3=(float((float)c3/(float)l.length)*100);
dd3=(float((float)d3/(float)l.length)*100);
ee3=(float((float)e3/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "物理 "<< "\t" << "\t" << a3 << "/" << (float)aa3 << "%" << "\t" <<"\t"<< b3 << "/" << (float)bb3 << "%" << "\t"<<"\t"
<< c3 << "/" << (float)cc3 << "%" << "\t"<<"\t" << d3 << "/" << (float)dd3 << "%" << "\t" <<"\t"
<< e3 << "/" << (float)ee3 << "%" << "\t" <<"\t"<< endl;
//生物
int a4=0,b4=0,c4=0,d4=0,e4=0;
float aa4,bb4,cc4,dd4,ee4;
for (int i=0;i<n;i++)
{
if(l.elem[i].shengwu<=100&&l.elem[i].shengwu>=90){
a4++;} //优秀
else if(l.elem[i].shengwu>=80) {
b4++;} //良好
else if (l.elem[i].shengwu>=70){
c4++; } //中等
else if (l.elem[i].shengwu>=60){
d4++;} //及格
else if(l.elem[i].shengwu<60){
e4++;} //不及格
}
aa4=(float((float)a4/(float)l.length)*100);
bb4=(float((float)b4/(float)l.length)*100);
cc4=(float((float)c4/(float)l.length)*100);
dd4=(float((float)d4/(float)l.length)*100);
ee4=(float((float)e4/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "生物 "<< "\t" << "\t" << a4 << "/" << (float)aa4 << "%" << "\t" <<"\t"<< b4 << "/" << (float)bb4 << "%" << "\t"<<"\t"
<< c4 << "/" << (float)cc4 << "%" << "\t"<<"\t" << d4 << "/" << (float)dd4 << "%" << "\t" <<"\t"
<< e4 << "/" << (float)ee4 << "%" << "\t" <<"\t"<< endl;
//化学
int a5=0,b5=0,c5=0,d5=0,e5=0;
float aa5,bb5,cc5,dd5,ee5;
for (int i=0;i<n;i++)
{
if(l.elem[i].huaxue<=100&&l.elem[i].huaxue>=90){
a5++;} //优秀
else if(l.elem[i].huaxue>=80) {
b5++;} //良好
else if (l.elem[i].huaxue>=70){
c5++; } //中等
else if (l.elem[i].huaxue>=60){
d5++;} //及格
else if(l.elem[i].huaxue<60){
e5++;} //不及格
}
aa5=(float((float)a5/(float)l.length)*100);
bb5=(float((float)b5/(float)l.length)*100);
cc5=(float((float)c5/(float)l.length)*100);
dd5=(float((float)d5/(float)l.length)*100);
ee5=(float((float)e5/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "化学 "<< "\t" << "\t" << a5 << "/" << (float)aa5 << "%" << "\t" <<"\t"<< b5 << "/" << (float)bb5 << "%" << "\t"<<"\t"
<< c5 << "/" << (float)cc5 << "%" << "\t"<<"\t" << d5 << "/" << (float)dd5 << "%" << "\t" <<"\t"
<< e5 << "/" << (float)ee5 << "%" << "\t" <<"\t"<< endl;
//政治
int a6=0,b6=0,c6=0,d6=0,e6=0;
float aa6,bb6,cc6,dd6,ee6;
for (int i=0;i<n;i++)
{
if(l.elem[i].zzhi<=100&&l.elem[i].zzhi>=90){
a6++;} //优秀
else if(l.elem[i].zzhi>=80) {
b6++;} //良好
else if (l.elem[i].zzhi>=70){
c6++; } //中等
else if (l.elem[i].zzhi>=60){
d6++;} //及格
else if(l.elem[i].zzhi<60){
e6++;} //不及格
}
aa6=(float((float)a6/(float)l.length)*100);
bb6=(float((float)b6/(float)l.length)*100);
cc6=(float((float)c6/(float)l.length)*100);
dd6=(float((float)d6/(float)l.length)*100);
ee6=(float((float)e6/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "政治 "<< "\t" << "\t" << a6 << "/" << (float)aa6 << "%" << "\t" <<"\t"<< b6 << "/" << (float)bb6 << "%" << "\t"<<"\t"
<< c6 << "/" << (float)cc6 << "%" << "\t" <<"\t"<< d6 << "/" << (float)dd6 << "%" << "\t" <<"\t"
<< e6 << "/" << (float)ee6 << "%" << "\t"<<"\t" << endl;
//dili
int a7=0,b7=0,c7=0,d7=0,e7=0;
float aa7,bb7,cc7,dd7,ee7;
for (int i=0;i<n;i++)
{
if(l.elem[i].dili<=100&&l.elem[i].dili>=90){
a7++;} //优秀
else if(l.elem[i].dili>=80) {
b7++;} //良好
else if (l.elem[i].dili>=70){
c7++; } //中等
else if (l.elem[i].dili>=60){
d7++;} //及格
else if(l.elem[i].dili<60){
e7++;} //不及格
}
aa7=(float((float)a7/(float)l.length)*100);
bb7=(float((float)b7/(float)l.length)*100);
cc7=(float((float)c7/(float)l.length)*100);
dd7=(float((float)d7/(float)l.length)*100);
ee7=(float((float)e7/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "地理 "<< "\t" << "\t" << a7 << "/" << (float)aa7 << "%" << "\t"<<"\t" << b7 << "/" << (float)bb7 << "%" << "\t"<<"\t"
<< c7 << "/" << (float)cc7 << "%" << "\t"<<"\t" << d7 << "/" << (float)dd7 << "%" << "\t" <<"\t"
<< e7 << "/" << (float)ee7 << "%" << "\t" <<"\t"<< endl;
//历史
int a8=0,b8=0,c8=0,d8=0,e8=0;
float aa8,bb8,cc8,dd8,ee8;
for (int i=0;i<n;i++)
{
if(l.elem[i].lishi<=100&&l.elem[i].lishi>=90){
a8++;} //优秀
else if(l.elem[i].lishi>=80) {
b8++;} //良好
else if (l.elem[i].lishi>=70){
c8++; } //中等
else if (l.elem[i].lishi>=60){
d8++;} //及格
else if(l.elem[i].lishi<60){
e8++;} //不及格
}
aa8=(float((float)a8/(float)l.length)*100);
bb8=(float((float)b8/(float)l.length)*100);
cc8=(float((float)c8/(float)l.length)*100);
dd8=(float((float)d8/(float)l.length)*100);
ee8=(float((float)e8/(float)l.length)*100);
cout.setf(ios::fixed);
cout<<setprecision(0);
cout << "历史 "<< "\t" << "\t" << a8 << "/" << (float)aa8 << "%" << "\t" << "\t"<< b8 << "/" << (float)bb8 << "%" << "\t"<< "\t"
<< c8 << "/" << (float)cc8 << "%" << "\t"<< "\t" << d8 << "/" << (float)dd8 << "%" << "\t" << "\t"
<< e8 << "/" << (float)ee8 << "%" << "\t"<< "\t" << endl;
return ok;
}
菜单
status menu(){ //菜单
char cz;
do{
cout<<"*******************************************************************************************"<<endl;
cout<<"* 欢迎使用学生成绩管理系统 *"<<endl;
cout<<"*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*"<<endl;
cout<<"* 1、输入学生成绩 *"<<endl;
cout<<"* 2、显示学生成绩 *"<<endl;
cout<<"* 3、查找学生成绩 *"<<endl;
cout<<"* 4、修改学生成绩 *"<<endl;
cout<<"* 5、删除学生成绩 *"<<endl;
cout<<"* 6、插入学生成绩 *"<<endl;
cout<<"* 7、统计各门课程平均分、最高分、最低分 *"<<endl;
cout<<"* 8、统计各门课程优秀、良好、中等、及格、不及格的人数及百分比 *"<<endl;
cout<<"* 0、退出管理系统 *"<<endl;
cout<<"*******************************************************************************************"<<endl;
cout<<"请输入您选择的操作:"<<endl;
cin>>cz;
if(cz>'8'||cz<'0'){
system("cls");
cout<<"- - - - - - 您选择的操作无效!!请重新输入0-8数字之间的操作。 - - - - - -"<<endl;
}
else
break;
}while(cz < '0' || cz > '8');
return (cz-'0');
}
运行结果如下:
main函数
int main(){
sqlist s;
initlist(s);
for(;;){
switch(menu()){
case 1: input(s); break;
case 2: show(s); break;
case 3: search(s); break;
case 4: alter(s); break;
case 5: delet(s); break;
case 6: insert(s); break;
case 7: grade(s); break;
case 8: people(s); break;
case 0: cout<<endl<<"- - - - - - - - - - - - - - 感谢您使用学生成绩管理系统 - - - - - - - - - - - - - - - -\n"<<endl; exit(0);
}
}
return 0;
}
总结
在做课程设计,正确分析题目需求非常重要,再构想菜单中的模块,对每个模块应该用什么形式去实现,这些都需要在编程之前构想好,才好去编写代码。将大致流程有了一个思路之后,我们就要去实现代码,并且要考虑到用户的使用感受,对每个模块的版面排版,我们所运用制表符去调整,还有一些符号,是显示页面更美观。
、
此次课设是和我的两个美丽的舍友(韦某和陆某)一起完成的,在完成此课设的过程中,也有参照了很多网上其他大佬的代码,还有很多不足的地方,欢迎大家批评指正