《c语言学生信息管理系统.doc》由会员分享,可在线阅读,更多相关《c语言学生信息管理系统.doc(46页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、优质文本#include#include#include#define MAX_S_NUM 100;struct stuTypechar name9;char gender3;char phone12;int age;float hight; struct stuType stuAry100;struct stuType Ary100;int n;FILE *fp;char ch;bool test=true;void GotoXY(int x,int y); void mainColumName();void DispColumName();void QueryColumName();voi
2、d QueryDispColumName();void QueryDispColumName1();void QueryName();void QueryName1();void QueryList();void DispErrorInfo();void ClDispInfo();void ClearInfo();void QuClearInfo();void ScanfInfo(stuType stu);void Input();void Query();void SortAry();void Modification();void statitics();/*主函数*/void main(
3、) while (test)/*ystem(cls);GotoXY(30,10); printf(同学通讯录管理系统顺序结构查询n); GotoXY(29,11); printf(=n); GotoXY(29,13); printf(1. 输入 2. 查询 3. 修改n); GotoXY(29,15); printf(4. 排序 5. 统计 6. 退出n); GotoXY(29,17); printf(=n); GotoXY(29,19); printf(请选择:); /getch();scanf(%d,&n); */mainColumName();if(n6)GotoXY(40,19);pr
4、intf(输入无此选项); test=!test; switch(n)case 1 :/system(cls);DispColumName(); Input();test=!test; break;case 2 : /system(cls);QueryColumName(); Query();test=!test; break;case 3 : /system(cls);Modification(); test=!test; break;case 4 :SortAry();test=!test; break;case 5 :statitics();test=!test; break;case
5、6 : system(cls); test=false; break;/*坐标定位*/void GotoXY(int x,int y)COORD c;c.X = x - 1;c.Y = y - 1;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);/*输入显示模块*/void DispColumName()system(cls);GotoXY(30,10);printf(请输入各项信息n);GotoXY(25,11);printf(=n); GotoXY(2,13);printf(姓名:);GotoXY(20,13);pr
6、intf(性别:);GotoXY(33,13);printf( 号:);GotoXY(55,13);printf(年龄:);GotoXY(65,13);printf(身高(m):);GotoXY(15,15);printf(是否继续输入(Y/*):);/*输入显示*/void Input()int i=0;bool a=true;/int num;fp = fopen (stu.dat, a);if (fp=NULL)printf(The file stu.datis opened filed);exit(1);int count=0;while(a)ScanfInfo(stuAry);Got
7、oXY(35,15);/scanf(%s,&ch);fflush(stdin);Arycount=stuAryi;fwrite(&stuAryi,sizeof(struct stuType), 1, fp); count+;ch = getchar();if(ch=Y|ch=y) / fwrite(&stuAryi,sizeof(struct stuType), 1, fp); / Arycount=stuAryi; / count+; / fclose(fp); ClearInfo(); DispColumName();else a=false; test=!test;/mainColumN
8、ame();count=count-1; fclose(fp);/*查询模块方式*/void Query()int m;GotoXY(11,9);scanf(%d,&m);fflush(stdin);switch (m)case 1 : QueryDispColumName(); QueryDispColumName1(); break; case 2 :QueryName();QueryName1(); break;case 3 :QueryList(); break;case 0 : /system(cls);test=!test; break;/*修改模块方式*/void Modific
9、ation()int m = 0;int i = 0;int count = 0;int b = 0;char ch ,search9;bool a=true;system(cls);GotoXY(30,6);printf(修改信息);GotoXY(10,7);printf(=);GotoXY(10,9);printf(=);GotoXY(13,8);printf(请输入要修改人姓名:);while (a) GotoXY(33,8); scanf(%s,search); fflush(stdin); fp = fopen(stu.dat,r); if (fp=NULL) printf(The
10、file stu.dat is opened filed!); exit(1); while(!feof(fp)fread(&Arycount,sizeof(struct stuType),1,fp);count+; fclose(fp);/while (a)/rewind(fp);/ while (!feof(fp)char *ch1=Aryi.name ,*ch2=search;for(i=0;icount;i+) /fread(&Arym,sizeof(struct stuType),1,fp); /char *ch1=Aryi.name ,*ch2=search; if (strcmp
11、(Aryi.name,search)=0) GotoXY(2,13); printf(姓名:); GotoXY(20,13); printf(性别:); GotoXY(33,13); printf( 号:); GotoXY(55,13); printf(年龄:); GotoXY(65,13); printf(身高(m):); GotoXY(8,13); scanf(%s,stuAryi.name); fflush(stdin); GotoXY(26,13); scanf(%s,stuAryi.gender);fflush(stdin); GotoXY(42,13); scanf(%s,stuA
12、ryi.phone); while(strlen(stuAryi.phone)!=11) DispErrorInfo(); GotoXY(25,19); printf( 号码输入错误,应为11为数字!); GotoXY(42,13); printf( ); GotoXY(42,13); scanf(%s,&stuAryi.phone); fflush(stdin); ClDispInfo(); GotoXY(25,19); printf( ); GotoXY(61,13); scanf(%d,&stuAryi.age); while(stuAryi.age120) DispErrorInfo(
13、); GotoXY(25,19); printf(年龄输入应在0-120之内); GotoXY(61,13); printf( ); GotoXY(61,13); scanf(%d,&stuAryi.age); fflush(stdin); ClDispInfo(); GotoXY(25,19); printf( ); GotoXY(75,13); scanf(%f,&stuAryi.hight); while (stuAryi.hight3) DispErrorInfo(); GotoXY(25,19); printf(身高应在0-3米之内);GotoXY(75,13); printf( )
14、; GotoXY(75,13); scanf(%f,&stuAryi.hight); fflush(stdin); Aryi=stuAryi;b+;/fwrite(&Aryi,sizeof(struct stuType), 1, fp); / fclose(fp); /count+;/fclose(fp); count=count-1;fp = fopen(stu.dat,w); for(i=0;icount;i+) fwrite(&Aryi,sizeof(struct stuType),1,fp); fclose(fp); if(b=0)GotoXY(37,8);printf(没有此项);
15、GotoXY(15,20); printf(是否继续修改(Y/*):); GotoXY(35,20); ch=getch(); fflush(stdin); if(ch=y|ch=Y) GotoXY(8,13); printf( );GotoXY(33,8);printf( ); GotoXY(26,13); printf( ); GotoXY(42,13); printf( ); GotoXY(61,13); printf( ); GotoXY(75,13); printf( ); else a=!a; test=!test;/*排序*/void SortAry()int i = 0;int
16、 a,b,c;system(cls); GotoXY(25,3);printf(数据年龄升序显示);GotoXY(5,4); printf(=); GotoXY(6,5); printf(姓名 性别 号 年龄 身高(m); GotoXY(5,20); printf(=);fp = fopen(stu.dat,r);if (fp=NULL)printf(The file stu.dat is opened filed!);exit(1);while(!feof(fp)fread(&Aryi,sizeof(struct stuType),1,fp);i+;i=i-1;for(a=0;ai-1;a+
17、)for(b=a+1;b=Aryb.age) c=Arya.age;Arya.age=Aryb.age;Aryb.age=c;for(a=0;ai;a+)GotoXY(5,7+a); printf(%s,Arya.name);fflush(stdin); GotoXY(18,7+a); printf(%s,Arya.gender);fflush(stdin); GotoXY(29,7+a); printf(%s,Arya.phone);fflush(stdin); GotoXY(47,7+a); printf(%d,Arya.age);fflush(stdin); GotoXY(55,7+a)
18、; printf(%1.2f,Arya.hight);fflush(stdin);GotoXY(10,21);printf(信息显示完毕,按Esc键返回上一层.);if(getche()=27)test=!test;/*统计模块*/void statitics()int i=0;int count=0;int a;float age , hight ,sum2=0 ,sum1=0; system(cls);GotoXY(15,5);printf(信息统计);GotoXY(5,6);printf(=); fp = fopen (stu.dat,r); if(fp=NULL)printf(The
19、file stu.dat is opened filed!);exit(1);while(!feof(fp)fread(&Aryi,sizeof(struct stuType),1,fp);i+;count+;fclose(fp);count=count-1;GotoXY(5,7);printf(班级总人数:%d,count);for(a=0;acount;a+)sum1+=Arya.age;sum2+=Arya.hight;age = float ( sum1 )/ count;hight = sum2/ count;GotoXY(5,8);printf(班级平均年龄是:%1.2f,age)
20、;GotoXY(5,9);printf(班级平均身高(m):%1.2f ,hight);GotoXY(5,11);printf(信息显示完毕,按Esc键返回上一层.);if(getche()=27)test=!test;/*输入模块显示信息*/void ScanfInfo(stuType stu) int i=0;GotoXY(8,13); scanf(%s,stui.name); fflush(stdin); GotoXY(26,13); scanf(%s,stui.gender);fflush(stdin); GotoXY(42,13); scanf(%s,stui.phone);whil
21、e(strlen(stui.phone)!=11)DispErrorInfo(); GotoXY(25,19);printf( 号码输入错误,应为11为数字!);GotoXY(42,13);printf( );GotoXY(42,13); scanf(%s,&stui.phone);fflush(stdin);ClDispInfo(); GotoXY(25,19);printf( ); GotoXY(61,13); scanf(%d,&stui.age);while(stui.age120)DispErrorInfo();GotoXY(25,19);printf(年龄输入应在0-120之内);
22、GotoXY(61,13);printf( );GotoXY(61,13);scanf(%d,&stui.age);fflush(stdin);ClDispInfo(); GotoXY(25,19);printf( ); GotoXY(75,13); scanf(%f,&stui.hight);while (stui.hight3)DispErrorInfo();GotoXY(25,19);printf(身高应在0-3米之内);GotoXY(75,13);printf( );GotoXY(75,13);scanf(%f,&stui.hight);fflush(stdin);ClDispInfo
23、(); GotoXY(25,19);printf( );/GotoXY(35,15);/scanf(%s,&ch);/*去除显示信息*/void ClearInfo()GotoXY(8,13);printf( );GotoXY(26,13);printf( );GotoXY(42,13);printf( );GotoXY(61,13);printf( );GotoXY(75,13);printf( );GotoXY(35,15);printf( );/*/ /*void ClearInfo1()GotoXY(40,13);printf( );GotoXY(8,15+b);printf( );G
24、otoXY(26,15+b);printf( );GotoXY(42,15+b);printf( );GotoXY(61,15+b);printf( );GotoXY(75,15+b);printf( );GotoXY(15,25);printf( ); */*主体框架模块*/ void mainColumName()system(cls); GotoXY(30,10); printf(同学通讯录管理系统顺序结构查询n); GotoXY(29,11); printf(=n); GotoXY(29,13); printf(1. 输入 2. 查询 3. 修改n); GotoXY(29,15); p
25、rintf(4. 排序 5. 统计 6. 退出n); GotoXY(29,17); printf(=n); GotoXY(29,19); printf(请选择:); /getch();scanf(%d,&n);/*提示错误信息*/void DispErrorInfo()GotoXY(33,17);printf(错误信息提示);GotoXY(25,18);printf(=n);test=!test;/*去除提示错误信息*/void ClDispInfo()GotoXY(33,17);printf( );GotoXY(25,18);printf( );/*查询模块框架*/void QueryCol
26、umName()system(cls);GotoXY(3,1);printf(1.顺序查询:);GotoXY(3,3);printf(2.按姓名查询:);GotoXY(3,5);printf(3.列表查询:);GotoXY(3,7);printf(0.结束查询);GotoXY(3,9);printf(请选择:);/*顺序查询模块框架*/ void QueryDispColumName()system(cls);GotoXY(30,10);printf(顺序显示通讯录中各该同学的信息n);GotoXY(25,11);printf(=n); GotoXY(2,13);printf(姓名:);Got
27、oXY(20,13);printf(性别:);GotoXY(33,13);printf( 号:);GotoXY(55,13);printf(年龄:);GotoXY(65,13);printf(身高(m):);GotoXY(15,15);printf(是否继续查询(Y/*):);/*顺序查询模块显示信息*/void QueryDispColumName1() int i=0;int m=0; bool a=true;char ch2;fp = fopen (stu.dat, r);if (fp=NULL)printf(The file stu.datis opened filed);exit(1
28、);while(!feof(fp)fread(&Arym,sizeof(struct stuType),1,fp); m+;m=m-1;while(im&a)GotoXY(8,13);printf(%s,Aryi.name); fflush(stdin); GotoXY(26,13); printf(%s,Aryi.gender); fflush(stdin); GotoXY(42,13); printf(%s,Aryi.phone); fflush(stdin); GotoXY(61,13);printf(%d,Aryi.age); fflush(stdin); GotoXY(75,13);
29、 printf(%1.2f,Aryi.hight);fflush(stdin); GotoXY(35,15);ch2=getchar(); if(ch2=Y|ch2=y) ClearInfo(); i+; else system(cls); a=!a; QueryColumName(); Query(); if(i=m) GotoXY(8,13); printf(%s,Aryi-1.name); GotoXY(26,13); printf(%s,Aryi-1.gender); GotoXY(42,13); printf(%s,Aryi-1.phone); GotoXY(61,13); printf(%d,Aryi-1.age); GotoXY(75,13); printf(%1.2f,Aryi-1.hight); GotoXY(8,15); printf( ); printf(已经查询到最后一条记录,按Esc返回上一层.);if(getche()=27) QueryColumName(); Query();ClearInfo();/*按姓名查询模块框架*/void QueryName()system(cls);GotoXY(15,10);printf(
限制150内