代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
成绩管理系统
作者:
Vurteon
/ 发布于
2013/10/24
/
730
//下面三行谁包含头文件 #include<stdio.h> #include<windows.h> #include<stdlib.h> //下面是宏定义,便于修改也可以简化代码 #define enter "\n\n\n\n\n" #define space " " #define choice "Please enter your choice:" #define land2 " ------------------------Wellcome to use the system----------------------------\n" #define land1 " ----------------------------------LAND----------------------------------------\n" #define ShowHeader1 "------------------------------------STUDENT------------------------------------\n" #define ShowHeader2 "| number | name | C | Math | Eng | sum | ave | minci|\n" #define ShowHeader4 "| number | name | C | Math | Eng | sum | ave | pro |\n" #define ShowHeader3 "|---------------|---------------|------|--------|-------|-------|------|------|\n" #define FORMAT " | %-10s |%-15s|%4d|%4d|%4d| %4d | %.2f |%4d |\n" FILE *fp,*fp1; //定义文件指针 struct ID //用户名ID结构体 { char IDCard[30]; }; //函数声明 void Wellcome(void); int Land(); int GetNumber(void); void Wrong(void); int CreatNewUser(); char*EnterNumber(); void Style(); int EnterSystem(char []); void menu(); void NewRecord(char []); void SearchRecord(char []); void ScanRecord(char str[]); void Reback(); int Sum(int C,int Math,int Eng); float Ave(int sum); int Sort(char str[]); //void quick_sort(student sort[] , int l, int r); //学生学习成绩信息结构体 typedef struct student { char number[20]; char name[10]; int unsigned C; int unsigned math; int unsigned eng; struct student *next; }*stu; //便利函数声明 struct student *BianLi(void); 下面是主函数体 /******这是一个学生分数管理系统,主要功能是********** *******记录,查看,删除等学生分数的信息。函数命名******** *******都是以功能来命名的,可以方便的找到相关功能********* *******的代码。 ****************学生分数管理系统**************** ******************编写者:康乐****************** ******************编写日期:2012 12 8*********** */ #include"KLC.h" //包含头文件 void main(void) { system("color 01"); Land(); } int LandSence() //将界面和数据操作分开,界面显示函数 { int number; system("cls"); //windows中的清屏函数 printf(enter); printf(land1); printf("\n\n"); printf(space); printf("1.creat a new ID\n\n"); //创建新的ID printf(space); printf("2.I already have a ID\n\n"); //如果用户有ID ,则直接输入选项进入 printf(" "); printf(choice); number = GetNumber(); //用户输入选择 return number; } /*函数功能,判断用户的输入,并进入相应 的流程 */ int Land() { int number = LandSence(); if(1 == number) CreatNewUser(); else if(2 == number) EnterNumber(); else { Wrong(); getchar(); Land(); } return 0; } /*因为有很多的地方需要用户输入相应的选项 *所以将用户输入单独的用一个函数写出,方便其他 *函数的调用. */ int GetNumber() { int number = 0; if(!scanf("%d",&number)) Wrong(); return number; } /* *检测用户输入是否早已存在 */ int CheckNumber(char str[]) { ID *output,put; output = (ID*)malloc(sizeof(ID)); fp = (fopen("enter","rb")); while((fread(output,sizeof(put),1,fp)) == 1) // 在文件中查询用户名 { if(strcmp(output->IDCard,str) == 0) { printf("The ID was used,Please choice other ID!"); fclose(fp); getchar();getchar(); system("cls"); return Land(); } } fclose(fp); return 0; } void Wrong() /*输出按键错误信息*/ { printf("\n\n\n***********Error:input has wrong! press any key to continue**********\n"); getchar(); } void EnterSystemSence() //界面函数 { system("CLS"); printf(enter); printf(land1); printf(space); printf("Please enter your ID:"); } /*函数功能:提示用户输入自己已经有的ID,进入相应的系统,并将 *用户的ID作为参数传递,以便其它相关函数的使用. */ char *EnterNumber() { EnterSystemSence(); char IDcard[30]; ID *output,put; output = (ID*)malloc(sizeof(ID)); int ID = 0,number = 0; scanf("%s",IDcard); // 输入用户名 if((fp=fopen("enter","rb")) == NULL) exit(1); while((fread(output,sizeof(put),1,fp)) == 1) // 在文件中查询用户名 { if(strcmp(output->IDCard,IDcard) == 0) { number++; printf(" ID is right ! press anykey to enter system !"); if((fp1 = fopen(IDcard,"ab")) == NULL) // 打开用户指定文件 { exit(1); } fclose(fp1); getchar(); getchar(); EnterSystem(IDcard); // 正式进入用户系统 } } if(0 == number) { fclose(fp); printf("\nNo Such a ID ,You can creat a New ID!"); //若果没有ID 则提示用户从新登陆或创建新的ID getchar();getchar(); Land(); } getchar(); fclose(fp); return IDcard; } /* *创建用户的ID,并向文件中写入ID数据 *并储存 */ int CreatNewUser() // 创建新用户ID { ID *input; input = (ID*)malloc(sizeof(ID)); // 在静态区申请内存空间 if((fp=fopen("enter","ab")) == NULL) { printf("Wrong"); exit(1); } Style(); printf("Please enter your new ID:"); scanf("%s",input->IDCard); CheckNumber(input->IDCard); fwrite(input,sizeof(ID),1,fp); // 向文件中写入用户创建的ID信息 fclose(fp); printf("\n\n 成功创建ID:%s",input->IDCard); return 0; } void Style(void) //一个公用的函数 { printf(enter); printf(space); } int EnterSystem(char str[]) { system("color 01"); menu(); // 列举用户选项 int number = GetNumber(); switch(number) //使用switch进行用户的输入检查 { case 1:NewRecord(str);break; case 2:SearchRecord(str);break; case 3:ScanRecord(str);break; case 4:EnterNumber();break; case 5:break; default: break; } return 0; } /* 用户选项列举函数 */ void menu() //主界面 { system("cls"); printf(enter); printf(land2); printf("\n"); //提供了五个选项,删除和修改在search中实现 printf(" 1.Iput new record 2.serch record\n\n"); printf(" 3.scan record 4.Login system\n\n"); printf(" 5.Quit\n\n"); printf(" Please enter your choice:"); } int CheckRecord(char str[],char number[]) { if((fp=fopen(str,"rb")) == NULL) { printf("Wrong"); exit(1); } student *Check; Check=(student*)malloc(sizeof(student)); while((fread(Check,sizeof(student),1,fp)) == 1) // 在文件中查询Record { if((strcmp(Check->number,number) == 0)) { printf("The student Record was exist!Press any key to return Menu."); getchar();getchar(); system("cls"); fclose(fp); return EnterSystem(str); } } fclose(fp); return 0; } /*新建学生信息,采用单链表进行获得用户输入数据*/ void NewRecord(char str[]) { system("cls"); printf(land2); char c; stu L; student *now ,*later,*read; L=(student*)malloc(sizeof(student)); //申请头结点 L -> next = NULL; now = L; while(true){ later = (student*)malloc(sizeof(student)); printf("Please enter number:"); scanf("%s",later->number); //这里由于是数组 所以名字就是地址 CheckRecord(str,later->number); printf("\nPlease enter name:"); scanf("%s",later->name); printf("\nPlease enter C record:"); scanf("%d",&later->C); //这里的later->C是变量!! printf("\nPlease enter math record:"); scanf("%d",&later->math); printf("\nPlease enter eng record:"); scanf("%d",&later->eng); now ->next = later; //交换节点 now = later; printf(" Go on wrinting ? (Y/N)"); if( (c = getchar()) == 'N'||(c = getchar()) == 'n' ) //提示用户是否继续输入 break; printf("\n"); } now->next = NULL; read = L->next; //从头节点开始遍历,向文件中写入信息 if((fp=fopen(str,"ab")) == NULL) { printf("Wrong"); exit(1); } while(read != NULL){ //向文件中写入信息 fwrite(read,sizeof(student),1,fp); read = read ->next; } fclose(fp); if(c == 'n') EnterSystem(str); } void SearchSence() { system("CLS"); printf("Please enter one of<number,name>\n"); printf(" Please enter your order:"); } /* 搜索学生信息,使用线性搜索的方法,因为是字符串,所以没法用二分查找*/ void SearchRecord(char str[]) { fp = fopen(str,"ab+"); char in[20]; int i = 0,c = 0; student *compare,*compare1,*write,*L = BianLi(); SearchSence(); scanf("%s",in); compare = L->next; while(compare != NULL){ if(strcmp(compare->number,in) == 0 || strcmp(compare->name,in) == 0) { int sum = Sum(compare->C,compare->math,compare->eng); int ave = Ave(sum); printf("\nstduent number:%s",compare->number); printf("\nstudent name:%s",compare->name); printf("\nC point:%d",compare->C); printf("\nMath point:%d",compare->math); printf("\nEng point:%d",compare->eng); printf("\nstudent Sum:%d\nstudent Ave:%d",sum,ave); printf("\n1.Change student imformation 2.Del student information 3.exit"); printf("\n\n Enter your choice :"); c = GetNumber(); if(1 == c) //修改学生成绩 { printf("\nPlease change C record:"); scanf("%d",&compare->C); printf("\nPlease change math record:"); scanf("%d",&compare->math); printf("\nPlease change eng record:"); scanf("%d",&compare->eng); } else if(2 == c) //删除学生成绩 { if(L->next == compare) L->next = compare->next; else compare1->next = compare->next; printf("Done!"); getchar();getchar(); } else if(3 == c) //退出查找系统 EnterSystem(str); } compare1 = compare; compare = compare->next; } fclose(fp); fp = fopen(str,"wb+"); write = L->next; while(write != NULL) { fwrite(write,sizeof(student),1,fp); write = write->next; } fclose(fp); if(0 == c) { printf("There is no the student information!Press any key to return."); getchar();getchar(); } EnterSystem(str); } void ScanRecordSence() //界面函数 { system("CLS"); printf(ShowHeader1); printf(ShowHeader2); printf(ShowHeader3); } void ScanRecordSence2() //界面函数 { system("CLS"); printf(ShowHeader1); printf(ShowHeader4); printf(ShowHeader3); } int ScanUnpass() { int num; printf("\n 1.Unpassn student 2.Pass student 3.Exit\n"); printf(" printf enter your older;"); num = GetNumber(); if(1 != num&& 2 != num&& 3 != num) Wrong(); return num; } /* 输出所有学生信息,而且统计几及格数,计算出及格率,而且给出排名 */ void ScanRecord(char str[]) { Sort(str); // 对文件的内容进行排序 ScanRecordSence(); int sum,xueci = 0,num; int MathF = 0,CF = 0,EngF = 0; float ave; stu read; if((fp=fopen(str,"rb")) == NULL) exit(1); stu L = BianLi(); read = L->next; while(read != NULL){ if(read->C >= 60) CF++; if(read->eng >= 60) EngF++; if(read->math >= 60) MathF++; sum = Sum(read->C,read->math,read->math); ave = Ave(sum); xueci++; printf("ssd%8d%8d%8d%9.2f%5d\n",read->number,read->name,read->C,read->math,read->eng,sum,ave,xueci); read = read->next; } printf("\n\n C has %d students pass!",CF);printf(" Math has %d students pass!",MathF);printf(" Eng has %d students pass!\n",EngF); printf("The pass of C:%d%%\n\n",100*CF/xueci);printf("The pass of Math:%d%%\n\n",100*MathF/xueci);printf("The pass of Eng:%d%%\n\n",100*EngF/xueci); /*下面是查看未及格人员*/ num = ScanUnpass(); if(1 == num) { system("color 04"); int a = 0,put = 0,i = 0; char Pro[3]; system("cls"); ScanRecordSence2(); read = L->next; while(read != NULL){ i = 0; if(read->C < 60) { a = 1; Pro[i] = 'C'; i++; } if(read->eng < 60) { a = 1; Pro[i] = 'E'; i++; } if(read->math < 60) { a = 1; Pro[i] = 'M'; i++; } if(1 == a) { sum = Sum(read->C,read->math,read->math); ave = Ave(sum); printf("ssd%8d%8d%8d%9.2f ",read->number,read->name,read->C,read->math,read->eng,sum,ave); while(put < i) { printf("%c ",Pro[put]); put++; } put = 0; printf("\n"); } read = read->next; } } else if(2 == num) { system("cls"); ScanRecordSence2(); read = L->next; while(read != NULL){ if(read->math >= 60&&read->eng >= 60&&read->C >= 60) { sum = Sum(read->C,read->math,read->math); ave = Ave(sum); printf("ssd%8d%8d%8d%9.2f PASS",read->number,read->name,read->C,read->math,read->eng,sum,ave); printf("\n"); } read = read->next; } } else if(3 == num) ; printf(" press enter to return !"); fclose(fp); getchar();getchar(); EnterSystem(str); } /*因为有好几个地方需要用到L,所有就单独的将其遍历,返回头结点的地址*/ struct student *BianLi() { student *now ,*later,*L; L=(student*)malloc(sizeof(student)); now = L; later = (student*)malloc(sizeof(student)); while((fread(later,sizeof(student),1,fp)) == 1) //建立一个带有数据的链表 { now ->next = later; now = later; later = (student*)malloc(sizeof(student)); } now->next = NULL; return L; } /*计算学生总分*/ int Sum(int C,int Math,int Eng) { int sum = (C + Math + Eng); return sum; } /*计算学生的平均成绩*/ float Ave(int sum) { float ave = (sum/3.0); return ave; } /*使用冒泡对学生成绩进行排序*/ int Sort(char str[]) { int count = 0,i = 0,j = 0,m = 0; struct student put[100]; student stu; student *now = put; if((fp=fopen(str,"rb+")) == NULL) exit(1); //打开失败处理 while(fread(&put[i],sizeof(student),1,fp) == 1) { count++; i++; } for(j = 0 ;j < count ;j++) { for(int q = 0 ; q < count - j ;q++) { int num1 = Sum(put[q].C,put[q].eng,put[q].math); int num2 = 0; if((q+1) < count-j) num2 = Sum(put[q+1].C,put[q+1].eng,put[q+1].math); //if(strcmp(put[q].number,put[q+1].number) > 0) //原来考虑到学生的利益,按学号排序,现在....没办法了.. if(num1 < num2) { stu = put[q]; put[q] = put[q+1]; put[q+1] = stu; } } } fseek(fp,0,0); for(j = 0; j < i; j++) { fwrite(&put[j],sizeof(student),1,fp); } fclose(fp); return 0; }
试试其它关键字
成绩管理系统
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Vurteon
贡献的其它代码
(
1
)
.
成绩管理系统
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3