|
|
#2
寒风中的细雨2010-04-11 22:52
程序还有待改进 有空在该下 发过去看看
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #define LEN sizeof( struct LNode ) struct Subject { int credit;//学分 int mark;//单科成绩分 }; typedef struct LNode { char name[12]; int number; struct Subject chinese; struct Subject english; struct Subject maths; struct LNode *next; }*Student; FILE *fp = NULL; Student L = NULL; void Creat_File();//读取或建立文件信息操作 void Save_File();//保存信息至文件 void Init();//初始化链表 void Insert();//添加学生信息 void Delete();//删除学生信息 void Output();//输出全部信息 void Change();//修改学生信息 void Credit_Ranking();//按学分平均排名从高到低排 float Count_Credit( Student p );//计算同学的评价学分成绩 void Mark_Ranking();//按总分进行排名 从高到低 int Count_Mark( Student p );//计算每位同学的总分 void Lesson_Analysis();//选择一门课程进行分析 并画出直方图 int main() { Init(); Creat_File(); while(1) { int i; printf("\n请按照下面提示进行相应的操作!\n"); printf("*按'1'进行添加学生信息*\n"); printf("*按'2'进行删除学生信息*\n"); printf("*按'3'输出全部学生信息*\n"); printf("*按'4'进行修改学生信息*\n"); printf("*按'5'按平均学分成绩从高到低排名*\n"); printf("*按'6'按总分进行从高到低排名*\n"); printf("*按'7'选择学科进行成绩分析*\n"); printf("*按'8'进行信息保存*\n"); printf("*按'9'推出系统*\n"); scanf("%d", &i ); switch( i ) { case 1: Insert(); break; case 2: Delete(); break; case 3: Output(); break; case 4: Change(); break; case 5: Credit_Ranking(); break; case 6: Mark_Ranking(); break; case 7: Lesson_Analysis(); break; case 8: Save_File(); break; case 9: exit(0); break; } } return 0; } //读取或建立文件信息操作 void Creat_File() { Student p; if( !(fp=fopen("d:\\studentmg.text", "r")) ) { //fp=fopen("d:\\studentmg.text", "w"); return; } else { while( !feof(fp) ) { p = (Student) malloc (LEN); fread( p, LEN, 1, fp ); p->next = L->next; L->next = p; } } fclose( fp ); } //保存信息至文件 void Save_File() { Student p = L->next; fp = fopen("d:\\studentmg.text", "w"); while( p ) { fwrite( p, LEN, 1, fp ); p = p->next; } fclose( fp ); } //初始化链表 void Init() { L = (Student) malloc (LEN); if( !L ) exit(0); L->next = NULL; } //添加学生信息 void Insert() { Student p; int amount; printf("输入要添加学生信息的人数:"); scanf("%d", &amount ); while( amount-- ) { p = (Student) malloc (LEN); printf("输入学生姓名:"); scanf("%s", p->name ); printf("输入学生的学号:"); scanf("%d", &p->number ); printf("分别输入语文学分和成绩:"); scanf("%d%d", &p->chinese.credit, &p->chinese.mark ); printf("分别输入英语学分和成绩:"); scanf("%d%d", &p->english.credit, &p->english.mark ); printf("分别输入数学学分和成绩:"); scanf("%d%d", &p->maths.credit, &p->maths.mark ); p->next = L->next; L->next = p; } } //删除学生信息 void Delete() { Student p = L->next, f = L; int num; if( !p ) { printf("系统中没有存储学生信息!"); return; } printf("输入要删除学生的学号:"); scanf("%d", &num ); while( p && (p->number!=num) ) { f = f->next; p = p->next; } if( !p ) printf("没有查到该学生的信息!"); else f->next = p->next; free( p ); printf("删除成功!\n"); } //输出全部信息 void Output() { Student p = L->next; if( !p ) { printf("系统中没有存储学生信息!"); return; } while( p != NULL ) { printf("学生姓名:%s\n", p->name ); printf("学生的学号:%d\n", p->number ); printf("语文学分和成绩:%d %d\n", p->chinese.credit, p->chinese.mark ); printf("英语学分和成绩:%d %d\n", p->english.credit, p->english.mark ); printf("数学学分和成绩:%d %d\n", p->maths.credit, p->maths.mark ); p = p->next; } free(p); } //修改学生信息 void Change() { Student p = L->next; int num; if( !p ) { printf("系统中没有存储学生信息!"); return; } printf("输入你要查找学生的学号:"); scanf("%d", &num ); while( p && (p->number!=num) ) p = p->next; if( !p ) printf("没有查到该学生的信息!"); else { printf("输入修改学生姓名为:"); scanf("%s", p->name ); printf("输入修改学生的学号为:"); scanf("%d", &p->number ); printf("分别输入修改语文学分和成绩为:"); scanf("%d%d", &p->chinese.credit, &p->chinese.mark ); printf("分别输入修改英语学分和成绩为:"); scanf("%d%d", &p->english.credit, &p->english.mark ); printf("分别输入修改数学学分和成绩为:"); scanf("%d%d", &p->maths.credit, &p->maths.mark ); } } //按学分平均排名从高到低排 void Credit_Ranking() { Student p = L->next, pf = p->next; void Exchang( Student &p1, Student &p2 ); if( !p ) { printf("系统中没有存储学生信息!"); return; } while( p ) { pf = p->next; while( fp ) { if( Count_Credit(p) < Count_Credit(pf) ) Exchang(p, pf); pf = pf->next; } p = p->next; } } //计算同学的平均学分成绩 float Count_Credit( Student p ) { float sum = 0.0; int total = 0; total += p->maths.credit * p->maths.mark; total += p->english.credit * p->english.mark; total += p->chinese.credit * p->chinese.mark; sum += float(p->maths.credit + p->english.credit + p->chinese.credit); sum = total/sum; return sum; } //按总分进行排名 从高到低 void Mark_Ranking() { void Exchang( Student &p1, Student &p2 ); Student p = L->next, pf = L->next; if( !p ) { printf("系统中没有存储学生信息!"); return; } while( p ) { pf = p->next; while( pf ) { if( Count_Mark(p) < Count_Mark(pf) ) Exchang(p, pf); pf = pf->next; } p = p->next; } } //计算每位同学的总分 int Count_Mark( Student p ) { int total = 0; total += p->maths.mark; total += p->english.mark; total += p->chinese.mark; return total; } //选择一门课程进行分析 并画出直方图 void Lesson_Analysis() { char string[10]; int a[6] = {0,0,0,0,0,0}; Student p = L->next; if( !p ) { printf("系统中没有存储学生信息!"); return; } printf("输入你要统计的课程名(english, chinese, maths):"); scanf("%s", string ); if( strcmp(string, "english") == 0 ) { while( p ) { a[0]++; if( (90<=p->english.mark) && (p->english.mark<=100) ) a[1]++; if( (80<=p->english.mark) && (p->english.mark<=89) ) a[2]++; if( (70<=p->english.mark) && (p->english.mark<=79) ) a[3]++; if( (60<=p->english.mark) && (p->english.mark<=69) ) a[4]++; if( p->english.mark<60 ) a[5]++; p = p->next; } } else if( strcmp(string, "maths") == 0 ) { while( p ) { a[0]++; if( (90<=p->maths.mark) && (p->maths.mark<=100) ) a[1]++; if( (80<=p->maths.mark) && (p->maths.mark<=89) ) a[2]++; if( (70<=p->maths.mark) && (p->maths.mark<=79) ) a[3]++; if( (60<=p->maths.mark) && (p->maths.mark<=69) ) a[4]++; if( p->maths.mark<60 ) a[5]++; p = p->next; } } else if( strcmp(string, "chinese") == 0 ) { while( p ) { a[0]++; if( (90<=p->chinese.mark) && (p->chinese.mark<=100) ) a[1]++; if( (80<=p->chinese.mark) && (p->chinese.mark<=89) ) a[2]++; if( (70<=p->chinese.mark) && (p->chinese.mark<=79) ) a[3]++; if( (60<=p->chinese.mark) && (p->chinese.mark<=69) ) a[4]++; if( p->chinese.mark<60 ) a[5]++; p = p->next; } } else return; for(int i=1; i<6; i++) { int j = a[i]; while( j ) { --j; putchar(3); } printf("%4.2f%c\n", float(a[i]/a[0])*100, 37 ); } } void Exchang( Student &p1, Student &p2 ) { struct LNode temp; strcpy(temp.name , p1->name); strcpy(p1->name, p2->name); strcpy(p2->name, temp.name); temp.number = p1->number; p1->number = p2->number; p2->number = temp.number; temp.chinese.credit = p1->chinese.credit; p1->chinese.credit = p2->chinese.credit; p2->chinese.credit = temp.chinese.credit; temp.chinese.mark = p1->chinese.mark; p1->chinese.mark = p2->chinese.mark; p2->chinese.mark = temp.chinese.mark; temp.english.credit = p1->english.credit; p1->english.credit = p2->english.credit; p2->english.credit = temp.english.credit; temp.english.mark = p1->english.mark; p1->english.mark = p2->english.mark; p2->english.mark = temp.english.mark; temp.maths.credit = p1->maths.credit; p1->maths.credit = p2->maths.credit; p2->maths.credit = temp.maths.credit; temp.maths.mark = p1->maths.mark; p1->maths.mark = p2->maths.mark; p2->maths.mark = temp.maths.mark; } |
用VC++可视化开发平台实现一个本班成绩管理与统计程序,要求界面友好,简洁大方,方便使用。程序的功能要求如下:
(1) 支持对话框形式的学生信息与课程成绩的录入、修改和删除;
(2) 计算本班每一位同学的学分成绩GPA( grade point average) 并排名,以此作为奖学金评定的参考依据;
(3) 对某一门课程,按照优(90-100)/良(80-89)/中(70-79)/及格(60-69)/不及格(60分以下)五档进行划分,统计在每一档的学 生人数和百分比例,并画出相应的饼图或直方图。
(4) 支持以文本格式导出学生的成绩记录,支持从文件中导入学生成绩记录;
(5) 其他成绩管理与统计所需的功能,可按自己的预想进行扩展。
(6) 演示时的模拟数据不少于15人;
牛啊!