学生成绩管理系统
1)至少能够管理100位同学的个人信息和成绩信息,个人信息和成绩需要有纠错功能。
2)个人信息包括:学号(53开头的实际学号8位),姓名(至少可以保存4个汉字),性别,民族,出生年月(年份为4位数字,月份为2位数字),行政职务(班长、学委、无)。
3)成绩信息包括:5门课程和总成绩的相关信息。5门课程包括:高级语言程序设计、高级语言程序设计实验、高级语言课程设计、面向对象程序设计、面向对象程序设计实验;每门课程的相关信息包括:课程名、课程学时、课程学分、所得成绩。总成绩的相关信息包括:平均成绩、加权平均成绩。
注:要明确区别百分制和五分制的成绩;在折算平均成绩和加权平均成绩时,五分制成绩中优秀、良好、中等、及格、不及格分别对应百分制成绩的95、85、75、65、0;平均成绩不考虑学分因素,为每门课程的算术平均值;加权平均成绩需要考虑学分因素,为每门课程的加权平均值。
一共有4个cpp
Student.cpp
Main.cpp
file1.cpp
file2.cpp
//Student.h
#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define WrongMark 0
#define N 20
enum POSITION {Monitor,Study_Commissar,None,Undefined_Position};
enum GENDER {Male,Female,Undefined_Gender};
struct Course
{
char Name[20];
int Time;
int Credit;
};
struct Student
{
int ID;
char Name[N];
bool Have_Name; //在有Name情况下Have_name为真,反之为假。 Name项不具备纠错功能
GENDER Gender; //0为男,1为女,2为出错
char Nationality[N];
bool Have_Nationality;//在有Nationality情况下Have_Nationality为真,反之为假。 Nationality项不具备纠错功能
int Birth; //-1为出错,反之为6位的出生年月(年4位月2位)
float Average;
float Weighted_Average;
POSITION Position; //0为班长,1为学委,2为无职务,3为出错
int Mark[5]; //出错时当-1算
Student* Next;
};
extern Course Cour[5];
extern int Input_From_Screen,Have_Open_Input;
extern FILE *File_Input,*File_Output;
extern Student *tail,*head;
extern bool ID_exist[10002];
extern bool Monitor_exist[102];
extern bool Study_Commissar_exist[102];
//-----------------------------------
void prepare();
void Start2();
void Start3();
//--------------------------------
void Init(); //【增加】
void Modify(); //【修改】
void Delete(); //【删除】
void Store_To_File(); //【存储】
void Print_Personal_Information();//【输出同学的个人信息】
void Compare_Two_Student();//【同行输出两个学生信息】
void Sort(Student**, int);
void PrintClassGrade(Student**,int);
void PrintClassCourseGrade(Student**,int,int);
void Print_Search_Mark(int,Student**);
void Print_Excellent_Mark(Student**, int);
void Print_Mark2(Student*,int);
void Print_Mark1(Student*,int);
void Print_Total_Mark(Student**, int);
//-------------------------------
void Delete_Student_Information(Student*,int);//only from screen
void Alter_Student_Information(Student*,int); //only from screen
void Get_New_Student_Information(Student*,int);
void Print_Student_Information(Student*,int);
void Calculate( Student* ) ;//计算单个同学成绩
//--------------------------------
int init_ID();
void init_Name(Student*);
void init_Gender(Student*);
void init_Nationality(Student*);
void init_Birth(Student*);
void init_Position(Student*,int);
void init_ALL_Mark(Student*);
int find_Related_Course();
void init_One_Mark(Student*);
void init_One_Specific_Mark(Student*,int);
void delete_Name(Student*);
void delete_Gender(Student*);
void delete_Nationality(Student*);
void delete_Birth(Student*);
void delete_Position(Student*,int);
void delete_One_Mark(Student*);
Student* find_Student(int);
void Print_Five(int mark);
#endif // STUDENT_H_INCLUDED
//main.cpp
#include"Student.h"
int Input_From_Screen;
int Have_Open_Input;
FILE *File_Input,*File_Output;
Student *tail=NULL,*head=NULL;
Course Cour[5];
bool ID_exist[10002];
bool Monitor_exist[102];
bool Study_Commissar_exist[102];
int main()
{
prepare();
Start2();
return 0;
}
void prepare()
{
printf("\n\n\n");
printf("\t********************************************************\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* 亲 欢迎使用学生管理系统!! *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t* 希望您玩得愉快!! *\n");
printf("\t* *\n");
printf("\t* *\n");
printf("\t********************************************************\n");
for (int i=1;i<=400000000;i++);
Input_From_Screen=1;
if (File_Input=fopen("D:\in.txt","r")) Have_Open_Input=1;
else {printf("读入文件未成功打开\n");
Have_Open_Input=0;
}
strcpy(Cour[0].Name,"高级语言程序设计");
strcpy(Cour[1].Name,"高级语言程序设计实验");
strcpy(Cour[2].Name,"高级语言课程设计");
strcpy(Cour[3].Name,"面向对象程序设计");
strcpy(Cour[4].Name,"面向对象程序设计实验");
Cour[0].Time=64;
Cour[1].Time=32;
Cour[2].Time=32;
Cour[3].Time=64;
Cour[4].Time=32;
Cour[0].Credit=4;
Cour[1].Credit=1;
Cour[2].Credit=1;
Cour[3].Credit=4;
Cour[4].Credit=1;
memset(ID_exist,0,sizeof(ID_exist));
memset(Monitor_exist,0,sizeof(Monitor_exist));
memset(Study_Commissar_exist,0,sizeof(Study_Commissar_exist));
}
void Start2()
{ system("cls");
while (1)
{
printf("\t***********************************************************\n");
printf("\t* *\n");
printf("\t* 请输入您需要的服务项目! *\n");
printf("\t* 1 增加新同学的信息 *\n");
printf("\t* 2 修改同学信息 *\n");
printf("\t* 3 删除同学信息 *\n");
printf("\t* 4 打印所有或部分同学的成绩信息 *\n");
printf("\t* 5 打印某同学的个人信息 *\n");
printf("\t* 6 存储信息到文件 *\n");
printf("\t* 0 退出 *\n");
printf("\t* *\n");
printf("\t***********************************************************\n");
int result2;
scanf("%d",&result2);
system("cls");
int exit_flag=0;
switch(result2)
{
case 1:Init();break;
case 2:Modify();break;
case 3:Delete();break;
case 4:Start3();break;
case 5:Print_Personal_Information();break;
case 6:Store_To_File();break;
case 0:exit_flag=1;break;
}
if (exit_flag==1)
{
system("cls");
printf("\t\t*************************************\n");
printf("\t\t* *\n");
printf("\t\t* *\n");
printf("\t\t* 程序结束,感谢使用 ^_^ *\n");
printf("\t\t* 欢迎下次使用! *\n");
printf("\t\t* *\n");
printf("\t\t* *\n");
printf("\t\t*************************************\n");
}
}
}
void Start3()
{
system("cls");
while(1)
{
printf("\t***********************************************************\n");
printf("\t* *\n");
printf("\t* 请输入您需要的服务项目! *\n");
printf("\t* 1 按照某位同学的学号或者姓名查找打印成绩 *\n");
printf("\t* 2 打印某班成绩 *\n");
printf("\t* 3 按照某科打印某班成绩 *\n");
printf("\t* 4 打印同学总成绩 *\n");
printf("\t* 5 打印优秀同学成绩 *\n");
printf("\t* 6 同行输出两个同学信息 *\n");
printf("\t* 0 退出 *\n");
printf("\t* *\n");
printf("\t***********************************************************\n");
int result3;
int exit_flage=0;
scanf("%d",&result3);
system("cls");
switch(result3)
{
case 1: printf("请输入查找方式 0按学号1 按照姓名");
int result3_1;
scanf("%d",&result3_1);
Print_Search_Mark(result3_1 ,&head);
break;
case 2:printf("请输入所需查找的班级");
int result3_2;
scanf("%d",&result3_2);
PrintClassGrade(&head,result3_2 );
break;
case 3:printf("请输入打印的班级和课程名称(0 高程1 高程实验2 课程设计3 面向对象程序设计4 面向对象实验)");
int result3_3_1,result3_3_2;
scanf("%d%d",&result3_3_1,&result3_3_2);
PrintClassCourseGrade(&head, result3_3_1, result3_3_2);
break;
case 4:printf("请输入打印成绩单的方法0按照学号顺序打印1按照平均成绩排名打印2按照加权平均成绩打印");
int result3_4;
scanf("%d",&result3_4);
Print_Total_Mark(&head, result3_4);
break;
case 5:printf("请输入打 印的班级和课程名称(0 高程1 高程实验2 课程设计3 面向对象程序设计4 面向对象实验)");
int result3_5;
scanf("%d",&result3_5);
Print_Excellent_Mark(&head, result3_5);
break;
case 6:Compare_Two_Student();
break;
case 0:exit_flage=1;break;
}
if(exit_flage==1)break;
}
}
//file1.cpp
#include"Student.h"
void Init() //【增加】
{
system("cls");
printf("\t\t*************************************\n");
printf("\t\t* 请选择输出方式 *\n");
printf("\t\t* 输入0:从文件读入 *\n");
printf("\t\t* 输入非0:从屏幕读入 *\n");
printf("\t\t*************************************\n");
scanf("%d",&Input_From_Screen);
system("cls");
if (Input_From_Screen)
{printf("将从屏幕读入,waiting...\n");
while (1)
{ printf("请输入新同学的id\n");
int id=init_ID();
if (id!=-1) {
printf("***********************************************************\n");
printf("*请输入该同学的个人信息:姓名,性别,民族,出生年月,行政职务*\n");
printf("*以及5门课程的成绩: *\n");
printf("* 高级语言程序设计 *\n");
printf("* 高级语言程序设计实验 *\n");
printf("* 高级语言课程设计 *\n");
printf("* 面向对象程序设计 *\n");
printf("* 面向对象程序设计实验 *\n");
printf("*亲!请注意:如果哪一项没有数据,请输入*代替 *\n");
printf("***********************************************************\n");
Student* newp=(Student*)malloc(sizeof(Student));
newp->ID=id;
Get_New_Student_Information(newp,id);
if (tail==NULL)
{
tail=newp;
head=tail;
}
else {tail->Next=newp;
tail=newp;
}
}
printf("继续读入新同学请输入1,退出请输入0\n");
int opt=-1;scanf("%d",&opt);system("cls");
while (opt!=0&&opt!=1){printf("您输入的不是0或1,继续读入新同学请输入1,退出请输入0\n"); scanf("%d",&opt);}
if (!opt) break;
}
printf("此次屏幕读入结束,waiting...\n");
}
if (Input_From_Screen==0)
{int have_input=0,should_input;
printf("将从文件读入,waiting...\n");
printf("请输入将读入几个同学的信息\n");
printf("输入n(n为大于0的整数),则读入n个\n");
printf("输入-1,则读到文件尾\n");
scanf("%d",&should_input);
while (1)
{ int id=init_ID();
if (id==-2) {printf("error---已读到文件尾\n"); break;}
if (id!=-1) {
Student* newp=(Student*)malloc(sizeof(Student));
newp->ID=id;
Get_New_Student_Information(newp,id);
if (tail==NULL)
{
tail=newp;
head=tail;
}
else {tail->Next=newp;
tail=newp;
}
have_input++;
printf("成功读入第%d个同学的信息,该同学id为%d\n",have_input,id);
}
if (id==-1) {printf("由于id错误,接下来读入的相应信息将作废\n");
Student* newp=(Student*)malloc(sizeof(Student));
Get_New_Student_Information(newp,0);
}
if (have_input==should_input) break;
}
printf("在这次文件读入中,共成功读入%d名同学的信息\n",have_input);
printf("此次文件读入结束,waiting...\n");
}
Input_From_Screen=1;
printf("\n\n");
}
void Modify() //【修改】
{ while (1)
{ printf("请输入要修改信息的同学的id\n");
int id=init_ID(),find_it=0;
for (Student *bl=head;bl!=NULL;bl=bl->Next)
if (bl->ID==id) {Alter_Student_Information(bl,id);find_it=1; break;}
if (!find_it) printf("额,此id不存在\n");
printf("继续修改其他同学请输入1,退出请输入0\n");
int opt=-1;scanf("%d",&opt);
system("cls");
while (opt!=0&&opt!=1){printf("您输入的不是0或1,继续修改其他同学请输入1,退出请输入0\n"); scanf("%d",&opt);}
if (!opt) break;
}
printf("\n\n");
}
void Delete() //【删除】
{ while (1)
{ printf("请输入要删除信息的同学的id\n");
int id=init_ID(),find_it=0;
for (Student *bl=head;bl!=NULL;bl=bl->Next)
if (bl->ID==id) {Delete_Student_Information(bl,id);find_it=1; break;}
if (!find_it) printf("额,此id不存在\n");
printf("继续删除其他同学请输入1,退出请输入0\n");
int opt=-1; scanf("%d",&opt);
system("cls");
while (opt!=0&&opt!=1){printf("您输入的不是0或1,继续删除其他同学请输入1,退出请输入0\n"); scanf("%d",&opt);}
if (!opt) break;
}
printf("\n\n");
}
void Store_To_File()//【存储】
{ File_Output=fopen("D:\out.txt","w");
printf("重新打开了输出文件\n");
int num=0;
for (Student *bl=head;bl!=NULL;bl=bl->Next)
{fprintf(File_Output,"%d %s ",bl->ID,bl->Name);
if (bl->Gender==0) fprintf(File_Output,"Male ");
else if (bl->Gender==1) fprintf(File_Output,"Female ");
else fprintf(File_Output,"* ");
fprintf(File_Output,"%s ",bl->Nationality);
fprintf(File_Output,"%d ",bl->Birth);
if (bl->Position==0) fprintf(File_Output,"Monitor ");
else if (bl->Position==1) fprintf(File_Output,"Study_Commissar ");
else if (bl->Position==2) fprintf(File_Output,"None ");
else fprintf(File_Output,"* ");
for (int i=0;i<5;i++)
fprintf(File_Output,"%d ",bl->Mark[i]);
num++;
fprintf(File_Output,"\n");
}
printf("成功写入%d个同学的信息到文件\n",num);
}
void Print_Personal_Information() //【输出同学的个人信息】
{ while (1)
{ system("cls");
printf("请输入要输出信息的同学的id\n");
int id=init_ID(),find_it=0;
for (Student *bl=head;bl!=NULL;bl=bl->Next)
if (bl->ID==id) {Print_Student_Information(bl,id);find_it=1; break;}
if (!find_it) printf("额,此id不存在\n");
printf("继续输出新同学请输入1,退出请输入0\n");
int opt=-1; scanf("%d",&opt);
while (opt!=0&&opt!=1){printf("您输入的不是0或1,继续输出其他同学请输入1,退出请输入0\n"); scanf("%d",&opt);}
if (!opt) break;
}
printf("\n\n");
}
void Compare_Two_Student()//【同行输出两个学生信息】
{ int id1,id2;
char ch[N];
Student*stu1,*stu2;
printf("请输入学生1的id\n");
while ((stu1=find_Student(id1=init_ID()))==NULL) printf("请输入学生1的id\n");
printf("请输入学生2的id\n");
while ((stu2=find_Student(id2=init_ID()))==NULL) printf("请输入学生2的id\n");
printf("-------------------------\n");
printf("\t学号: %d\t%d\n",id1,id2);
printf("\t姓名: %s\t%s\n",stu1->Name,stu2->Name);
for (int i=0;i<5;i++)
printf("\t%s: %d\t%d\n",Cour[i].Name,stu1->Mark[i],stu2->Mark[i]);
printf("-------------------------\n");
printf("按任意键退出程序\n");
scanf("%s",ch);
}
//计算平均成绩和加权
void Calculate(Student *p)
{
p->Average=(p->Mark[0]+p->Mark[1]+p->Mark[2]+p->Mark[3]+p->Mark[4])/5.0;
p->Weighted_Average=(4*p->Mark[0]+p->Mark[1]+p->Mark[2]+4*p->Mark[3]+p->Mark[4])/11.0;
}
/********************************************************************************************************************************/
bool Is_Integer(char *str)
{ int len=strlen(str);
for (int i=0;i<len;i++)
if (str[i]<'0'||str[i]>'9') return 0;
return 1;
}
int init_ID()
{ char now_id[N];
int eof;
if (Input_From_Screen) eof=(scanf("%s",now_id)==EOF);
else eof=(fscanf(File_Input,"%s",now_id)==EOF);
if (eof==1) return -2;
int val;
if (Is_Integer(now_id)&&strlen(now_id)==8&&now_id[0]=='5'&&now_id[1]=='3'&&now_id[2]=='1'&&now_id[3]=='2')
{ val=atoi(now_id);
if (val%100==0) {val=-1;printf("error!---Undefined_id\n");}
else if (val/100%100==0) {val=-1;printf("error!---Undefined_id\n");}
}
else {val=-1;printf("error!---Undefined_id\n");}
if (ID_exist[val%10000]==1)
{ val=-1;
printf("error!---have beed exist id\n");
}
if (val!=-1) ID_exist[val%10000]=1;
return val;
}
void init_Name(Student* st)//读入姓名
{ if (Input_From_Screen) scanf("%s",st->Name);else fscanf(File_Input,"%s",st->Name);
st->Have_Name=1;
}
void init_Gender(Student* st)//读入性别,看是否是Male、Female两者之一,若不是则报错
{ char now_gender[N];
if (Input_From_Screen) scanf("%s",now_gender);else fscanf(File_Input,"%s",now_gender);
if (strcmp(now_gender,"Male")==0) st->Gender=Male;
else if (strcmp(now_gender,"Female")==0) st->Gender=Female;
else {st->Gender=Undefined_Gender;printf("error!---Undefined_Gender\n");}
}
void init_Nationality(Student* st)//读入民族
{ if (Input_From_Screen) scanf("%s",st->Nationality);else fscanf(File_Input,"%s",st->Nationality);
st->Have_Nationality=1;
}
void init_Birth(Student* st)//读入出生年月,若出现以下任一种情况则报错(读入不为整数|出生年份大于2013或小于1000|出生月份大于12或小于1)
{ char now_birth[N];
if (Input_From_Screen) scanf("%s",now_birth);else fscanf(File_Input,"%s",now_birth);
if (Is_Integer(now_birth))
{int val=atoi(now_birth);
int month=val%100;
int year=val/100;
if (year>2013||year<1000||month>12||month<1)
{st->Birth=-1;printf("error!---Undefined_birth\n");}
else st->Birth=val;
}
else {st->Birth=-1;printf("error!---Undefined_birth\n");}
}
void init_Position(Student* st,int now_class)//读入职位,看是否为Monitor、Study_Commissar、None三者之一,若不是则报错
{ char now_pos[N];
if (Input_From_Screen) scanf("%s",now_pos);else fscanf(File_Input,"%s",now_pos);
if (strcmp(now_pos,"Monitor")==0)
{ if (Monitor_exist[now_class])
{printf("error---this class Monitor already existed\n");
st->Position=Undefined_Position;
return;
}
st->Position=Monitor;
Monitor_exist[now_class]=1;
printf("!%d班的班长有人当了\n",now_class);
}
else if (strcmp(now_pos,"Study_Commissar")==0)
{
{ if (Study_Commissar_exist[now_class])
{printf("error---this class Study_Commissar already existed\n");
st->Position=Undefined_Position;
return;
}
st->Position=Study_Commissar;
Study_Commissar_exist[now_class]=1;
printf("!%d班的学委有人当了\n",now_class);
}
}
else if (strcmp(now_pos,"None")==0) st->Position=None;
else {st->Position=Undefined_Position;printf("error!---Undefined_Position\n");}
}
void init_One_Specific_Mark(Student *st,int i)//读入成绩,若读入不为整数或成绩大于100或成绩小于0则报错,并且该门成绩计为-1
{
char now_mark[N];
if (Input_From_Screen) scanf("%s",now_mark);else fscanf(File_Input,"%s",now_mark);
if (Cour[i].Credit==4)
{if (Is_Integer(now_mark))
{int val=atoi(now_mark);
if (val>100||val<0)
{st->Mark[i]=WrongMark;printf("error!---Undefined_%s_mark\n",Cour[i].Name);}
else st->Mark[i]=val;
}
else
{st->Mark[i]=WrongMark;printf("error!---Undefined_%s_mark\n",Cour[i].Name);}
}
if (Cour[i].Credit==1)
{
int len=strlen(now_mark);
if (len!=1) {st->Mark[i]=WrongMark;printf("error!---Undefined_%s_mark\n",Cour[i].Name); return;}
if (now_mark[0]=='A'){st->Mark[i]=95;return;}
if (now_mark[0]=='B'){st->Mark[i]=85;return;}
if (now_mark[0]=='C'){st->Mark[i]=75;return;}
if (now_mark[0]=='D'){st->Mark[i]=65;return;}
if (now_mark[0]=='E'){st->Mark[i]=0; return;}
st->Mark[i]=WrongMark;
printf("error!---Undefined_%s_mark\n",Cour[i].Name);
}
}
void init_ALL_Mark(Student* st)//依次读入高程、高程实验、高程设计、面向、面向实验五门课的成绩
{ for (int i=0;i<5;i++)
init_One_Specific_Mark(st,i);
}
int find_Related_Course()//找到要修改的课程的对应编号
{ char now_cour[N];
if (Input_From_Screen) scanf("%s",now_cour);else fscanf(File_Input,"%s",now_cour);
int i;
for (i=0;i<5;i++)
if (strcmp(Cour[i].Name,now_cour)==0)break;
if (i==5) {printf("error---no related course\n"); return -1;}
return i;
}
void init_One_Mark(Student* st) //读人某一门成绩,先找到其对应的0-4之间的编号,再具体读入
{ int i=find_Related_Course();
if (i!=-1) init_One_Specific_Mark(st,i);
}
void delete_Name(Student* st)
{ st->Have_Name=0;
}
void delete_Gender(Student* st)
{ st->Gender=Undefined_Gender;
}
void delete_Nationality(Student* st)
{ st->Have_Nationality=0;
}
void delete_Birth(Student* st)
{ st->Birth=-1;
}
void delete_Position(Student* st,int now_class)
{ if (st->Position==Monitor)
{Monitor_exist[now_class]=0;
printf("!%d班的班长空出来了\n",now_class);
}
if (st->Position==Study_Commissar)
{Study_Commissar_exist[now_class]=0;
printf("!%d班的学委空出来了\n",now_class);
}
st->Position=Undefined_Position;
}
void delete_One_Mark(Student* st)//删除某一门成绩,先找到其对应的0-4之间的编号,再删除
{ int i=find_Related_Course();
if (i!=-1)st->Mark[i]=-1;
}
Student* find_Student(int id)
{
for (Student *p=head;p!=NULL;p=p->Next)
if (p->ID==id) return p;
Student* p=NULL;
return p;
}
void Alter_Student_Information(Student* st,int id) //only from screen
{ printf("请输入想更改的项目对应的编号\n");
int opt;
while (1)
{ printf("\t姓名>>0 性别>>1 民族>>2 出生年月>>3 职位>>4 成绩>>5 不想修改了>>6\n");
scanf("%d",&opt);
if (opt==0)init_Name(st);
if (opt==1)init_Gender(st);
if (opt==2)init_Nationality(st);
if (opt==3)init_Birth(st);
if (opt==4)init_Position(st,id/100%100);
if (opt==5){init_One_Mark(st);Calculate(st);}
if (opt==6)return;
}
}
void Delete_Student_Information(Student* st,int id) //only from screen
{ printf("请输入想删除的项目对应的编号\n");
int opt;
while (1)
{ printf("\t姓名>>0 性别>>1 民族>>2 出生年月>>3 职位>>4 成绩>>5 不想再删了>>6\n");
scanf("%d",&opt);
if (opt==0)delete_Name(st);
if (opt==1)delete_Gender(st);
if (opt==2)delete_Nationality(st);
if (opt==3)delete_Birth(st);
if (opt==4)delete_Position(st,id/100%100);
if (opt==5){delete_One_Mark(st);Calculate(st);}
if (opt==6)return;
}
}
void Get_New_Student_Information(Student* st,int id)
{ init_Name(st);
init_Gender(st);
init_Nationality(st);
init_Birth(st);
init_Position(st,id/100%100);
init_ALL_Mark(st);
Calculate(st);
st->Next=NULL;
printf("亲!如果输入的信息有错误,请在稍后调用修改函数进行修改\n");
}
void Print_Student_Information(Student* st,int id) //only from screen
{ printf("-------------------------\n");
printf("下面将输出编号为%d的同学的个人信息\n",id);
printf("姓名:"); if (st->Have_Name) printf("%s\n",st->Name); else printf("未录入\n");
printf("性别:"); if (st->Gender==0) printf("男\n");
else if (st->Gender==1) printf("女\n");
else printf("未录入\n");
printf("民族:"); if (st->Have_Nationality) printf("%s\n",st->Nationality); else printf("未录入\n");
printf("出生年月:"); if (st->Birth!=-1) printf("%d\n",st->Birth); else printf("未录入\n");
printf("职位:"); if (st->Position==0) printf("班长\n");
else if (st->Position==1) printf("学委\n");
else if (st->Position==2) printf("无\n");
else printf("未录入\n");
printf("下面将输出编号为%d的同学的成绩信息\n",id);
for (int i=0;i<5;i++)
printf("%s :%d\n",Cour[i].Name,st->Mark[i]);
printf("-------------------------\n");
printf("\n\n");
}
//File2.cpp
#include"Student.h"
//排序函数
//排序方式 0.按学号排序;1.按姓名排序;2.按Mark1排序;3.按Mark2排序
// 4.按Mark3排序;5.按Mark4排序;6.按Mark5排序;7.按平均成绩排序
// 8.按加权平均成绩排序
void Sort(struct Student** head, int SortStyle)
{
struct Student* First;//有序链表的头指针
struct Student* Tail;//有序链表的尾指针
struct Student* p_Min;//当前最小的前驱指针
struct Student* Min;//当前最小的指针
struct Student* p;//当前比较的节点
First = NULL;
while(*head != NULL)//在链表中找到最小值
{
for(p = *head, Min = *head; p->Next != NULL; p = p->Next)
{
switch(SortStyle)
{
case 0:
if(p->Next->ID < Min->ID)//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 1:
if((strcmp(p->Next->Name , Min->Name)) < 0)//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 2:
if(p->Next->Mark[0] > Min->Mark[0])//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 3:
if(p->Next->Mark[1] > Min->Mark[1])//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 4:
if(p->Next->Mark[2] > Min->Mark[2])//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 5:
if(p->Next->Mark[3] > Min->Mark[3])//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 6:
if(p->Next->Mark[4] > Min->Mark[4])//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 7:
if(p->Next->Average > Min->Average)//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
case 8:
if(p->Next->Weighted_Average > Min->Weighted_Average)//找到了更小的节点
{
p_Min = p;//保存当前最小的前驱指针
Min = p->Next;//保存当前最小的指针
}
break;
default:
printf("科目选择错误,排序失败!\n");
}
}
//添加到有序链表中
if(First == NULL)//有序表是空表
{First = Min;
Tail = Min;
}
else//有序表有节点
{Tail->Next = Min;
Tail = Min;//Tail = Tail->Next;
}
//在原表中移除已添加的Min
if(Min == *head)
{
(*head) = (*head)->Next;
}
else
{
p_Min->Next = Min->Next;
}
}
//排序结束,得到有序链表,返回
if(First != NULL)
{
Tail->Next = NULL;
}
*head = First;
}
void Print_Five(int mark)
{
if(mark == 95)
{
printf("优秀\t\t");
}else if(mark == 85)
{
printf("良好\t\t");
}else if(mark == 75)
{
printf("中等\t\t");
}else if(mark == 65)
{
printf("及格\t\t");
}else if(mark == 0)
{
printf("不及格\t\t");
}
}
//按学号打印某班成绩单
void PrintClassGrade(struct Student** head, int Class){
Sort(head,0);
int count = 0;
for (struct Student *p = *head; p != NULL; p = p->Next){
if (p->ID / 100 % 100 == Class)
{
count++;
if(count == 1)
{
printf("学号\t\t姓名\t高程\t高程实验\t高级设计\t面向对象\t面向对象实验\t平均成绩\t加权平均\n");
}
printf("%d\t%s\t%d\t", p->ID,p->Name,p->Mark[0]);
Print_Five(p->Mark[1]);
Print_Five(p->Mark[2]);
printf("%d\t\t",p->Mark[3]);
Print_Five(p->Mark[4]);
printf("%.2f\t\t%.2f\n", p->Average, p->Weighted_Average);
}
}
if(count == 0)
{
printf("非常抱歉,暂时没有录入该班级成绩信息!\n");
}
}
//按某课程成绩打印某班成绩单
void PrintClassCourseGrade(struct Student** head, int Class, int course)
{
Sort(head,course+2);
int count = 0;
for(struct Student* p = *head; p != NULL; p = p->Next)
{
if(p->ID / 100 % 100 == Class)
{
count++;
if(count == 1)
{
printf("学号\t\t姓名\t");
printf("%s\n",Cour[course
].Name);
}
printf("%d\t%s\t", p->ID, p->Name);
if(Cour[course].Credit == 1)
{
Print_Five(p->Mark[course]);
printf("\n");
}else
{
printf("%d\n", p->Mark[course]);
}
}
}
if(count == 0)
{
printf("非常抱歉,暂时没有录入该班级成绩信息!\n");
}
}
void Print_Mark1(Student* p,int a_or_wa)//打印一个人的成绩0.包括平均成绩,1,包括加权平均成绩
{
printf("学号\t\t姓名\t高程\t高程实验\t高级设计\t面向对象\t面向对象实验\t");
if(a_or_wa == 0){
printf("平均成绩\n");
}else
{
printf("加权平均成绩\n");
}
printf("%d\t%s\t%d\t", p->ID,p->Name,p->Mark[0]);
Print_Five(p->Mark[1]);
Print_Five(p->Mark[2]);
printf("%d\t\t",p->Mark[3]);
Print_Five(p->Mark[4]);
if(a_or_wa == 0){
printf("%.2f\n", p->Average);
}else
{
printf("%.2f\n", p->Weighted_Average);
}
}
void Print_Mark2(Student* p,int a_or_wa)//打印一个人的成绩0.包括平均成绩,1,包括加权平均成绩
{
printf("学号\t\t姓名\t高程\t高程学分\t高程实验\t高程实验学分\t高级设计\t高级设计学分\t面向对象\t面向对象学分\t面向对象实验\t面向对象实验学分\t");
if(a_or_wa == 0){
printf("平均成绩\n");
}else
{
printf("加权平均成绩\n");
}
printf("%d\t%s\t%d\t%d\t\t", p->ID,p->Name,p->Mark[0],Cour[0].Credit);
Print_Five(p->Mark[1]);
printf("%d\t\t",Cour[1].Credit);
Print_Five(p->Mark[2]);
printf("%d\t\t",Cour[2].Credit);
printf("%d\t\t%d\t\t",p->Mark[3],Cour[3].Credit);
Print_Five(p->Mark[4]);
printf("%d\t\t\t",Cour[4].Credit);
if(a_or_wa == 0){
printf("%.2f\n", p->Average);
}else
{
printf("%.2f\n", p->Weighted_Average);
}
}
void Print_Search_Mark( int ID_or_Name ,Student** head)//按照学号(0)或姓名(1)输出当前平均成绩排名,加权成绩排名,
{
int ID = 0;
char Name[20] = "no name";
if(ID_or_Name == 0)
{
printf("请输入你想要查找的学号(8位数):");
scanf("%d",&ID);
}else
{
printf("请输入你想要查找的姓名:");
scanf("%s",Name);
}
Sort(head,7);
Student * p = *head;
int count = 1;
bool flag = false;
while(p != NULL){
if(p->ID == ID || strcmp(p->Name ,Name) == 0){
flag = true;
Print_Mark1(p,0);
printf("该同学当前平均成绩排名为:%d\n",count);
break;
}
count++;
p = p->Next;
}
if(!flag){
printf("对不起,暂时没有录入该生的信息!");
}
count = 1;
flag = false;
Sort(head,8);
p = *head;
while(p != NULL){
if(p->ID == ID || strcmp(p->Name ,Name) == 0)
{
flag = true;
Print_Mark2(p,1);
printf("该同学当前加权平均成绩排名为:%d\n",count);
break;
}
count++;
p = p->Next;
}
if(!flag){
printf("对不起,暂时没有录入该生成绩!");
}
}
void Print_Excellent_Mark(Student** head, int course)//打印优秀同学成绩信息,0,1,2,3,4代表五门成绩
{
int count = 0;
Sort(head,0);
for (struct Student *p = *head; p != NULL; p = p->Next){
if (p->Position !=2&&p->Position !=3&& p->Mark[course] >= 90)//<=100
{
count++;
if(count == 1)
{
printf("学号\t\t姓名\t高程\t高程实验\t高级设计\t面向对象\t面向对象实验\t平均成绩\t加权平均\n");
}
printf("%d\t%s\t%d\t", p->ID,p->Name,p->Mark[0]);
Print_Five(p->Mark[1]);
Print_Five(p->Mark[2]);
printf("%d\t\t",p->Mark[3]);
Print_Five(p->Mark[4]);
printf("%.2f\t\t%.2f\n", p->Average, p->Weighted_Average);
}
}
if(count == 0)
{
printf("非常抱歉,暂时没有录入优秀同学的信息!\n");
}
}
void Print_Total_Mark(Student** head, int SortStyle)//打印系统中所有同学的成绩单[总成绩单]0.按学号打印
{ //1.按平均成绩打印;2,按加权平均成绩打印
switch(SortStyle)
{
case 0:
Sort(head,0);
break;
case 1:
Sort(head,7);
break;
case 2:
Sort(head,8);
break;
default:
printf("选择排序方式错误!"); return;
}
if(head != NULL){
printf("学号\t\t姓名\t高程\t高程实验\t高级设计\t面向对象\t面向对象实验\t平均成绩\t加权平均\n");
for (struct Student *p = *head; p != NULL; p = p->Next){
printf("%d\t%s\t%d\t", p->ID,p->Name,p->Mark[0]);
Print_Five(p->Mark[1]);
Print_Five(p->Mark[2]);
printf("%d\t\t",p->Mark[3]);
Print_Five(p->Mark[4]);
printf("%.2f\t\t%.2f\n", p->Average, p->Weighted_Average);
}
}else
{
printf("对不起,系统暂时没有录入信息。");
}
}