c语言学生信息管理系统.docx
- 文档编号:12289221
- 上传时间:2023-04-17
- 格式:DOCX
- 页数:38
- 大小:20.24KB
c语言学生信息管理系统.docx
《c语言学生信息管理系统.docx》由会员分享,可在线阅读,更多相关《c语言学生信息管理系统.docx(38页珍藏版)》请在冰豆网上搜索。
c语言学生信息管理系统
#include
#include
#include
#defineMAX_S_NUM100;
structstuType
{
charname[9];
chargender[3];
charphone[12];
intage;
floathight;
};
structstuTypestuAry[100];
structstuTypeAry[100];
intn;
FILE*fp;
charch;
booltest=true;
voidGotoXY(intx,inty);
voidmainColumName();
voidDispColumName();
voidQueryColumName();
voidQueryDispColumName();
voidQueryDispColumName1();
voidQueryName();
voidQueryName1();
voidQueryList();
voidDispErrorInfo();
voidClDispInfo();
voidClearInfo();
voidQuClearInfo();
voidScanfInfo(stuTypestu[]);
voidInput();
voidQuery();
voidSortAry();
voidModification();
voidstatitics();
/***********主函数************/
voidmain(){
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(n<1||n>6){
GotoXY(40,19);
printf("输入无此选项");
test=!
test;
}
switch(n){
case1:
{
//system("cls");
DispColumName();
Input();
test=!
test;
}break;
case2:
{
//system("cls");
QueryColumName();
Query();
test=!
test;
}break;
case3:
{
//system("cls");
Modification();
test=!
test;
}break;
case4:
{
SortAry();
test=!
test;
}break;
case5:
{
statitics();
test=!
test;
}break;
case6:
{system("cls");test=false;}break;
}
}
}
/***********坐标定位************/
voidGotoXY(intx,inty){
COORDc;
c.X=x-1;
c.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
/***********输入显示模块*************/
voidDispColumName(){
system("cls");
GotoXY(30,10);
printf("请输入各项信息\n");
GotoXY(25,11);
printf("========================\n");
GotoXY(2,13);
printf("姓名:
");
GotoXY(20,13);
printf("性别:
");
GotoXY(33,13);
printf("手机号:
");
GotoXY(55,13);
printf("年龄:
");
GotoXY(65,13);
printf("身高(m):
");
GotoXY(15,15);
printf("是否继续输入(Y/*):
");
}
/************输入显示************/
voidInput(){
inti=0;
boola=true;
//intnum;
fp=fopen("stu.dat","a");
if(fp==NULL)
{
printf("Thefile\"stu.dat\"isopenedfiled");
exit
(1);
}
intcount=0;
while(a){
ScanfInfo(stuAry);
GotoXY(35,15);
//scanf("%s",&ch);
fflush(stdin);
Ary[count]=stuAry[i];
fwrite(&stuAry[i],sizeof(structstuType),1,fp);
count++;
ch=getchar();
if(ch=='Y'||ch=='y')
{
//fwrite(&stuAry[i],sizeof(structstuType),1,fp);
//Ary[count]=stuAry[i];
//count++;
//fclose(fp);
ClearInfo();
DispColumName();
}
else
{a=false;
test=!
test;
//mainColumName();
}
}
count=count-1;
fclose(fp);
}
/***********查询模块方式**********/
voidQuery()
{
intm;
GotoXY(11,9);
scanf("%d",&m);
fflush(stdin);
switch(m)
{
case1:
{
QueryDispColumName();
QueryDispColumName1();
}break;
case2:
{
QueryName();
QueryName1();
}break;
case3:
{
QueryList();
}break;
case0:
{
//system("cls");
test=!
test;
}break;
}
}
/***********修改模块方式***********/
voidModification()
{
intm=0;
inti=0;
intcount=0;
intb=0;
charch,search[9];
boola=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("Thefile\"stu.dat\"isopenedfiled!
");
exit
(1);
}
while(!
feof(fp))
{
fread(&Ary[count],sizeof(structstuType),1,fp);
count++;
}
fclose(fp);
//while(a)
//{
//rewind(fp);
//while(!
feof(fp))
char*ch1=Ary[i].name,*ch2=search;
for(i=0;i { //fread(&Ary[m],sizeof(structstuType),1,fp); //char*ch1=Ary[i].name,*ch2=search; if(strcmp(Ary[i].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",stuAry[i].name); fflush(stdin); GotoXY(26,13); scanf("%s",stuAry[i].gender); fflush(stdin); GotoXY(42,13); scanf("%s",stuAry[i].phone); while(strlen(stuAry[i].phone)! =11) { DispErrorInfo(); GotoXY(25,19); printf("手机号码输入错误,应为11为数字! "); GotoXY(42,13); printf(""); GotoXY(42,13); scanf("%s",&stuAry[i].phone); } fflush(stdin); ClDispInfo(); GotoXY(25,19); printf(""); GotoXY(61,13); scanf("%d",&stuAry[i].age); while(stuAry[i].age<0||stuAry[i].age>120) { DispErrorInfo(); GotoXY(25,19); printf("年龄输入应在0-120之内"); GotoXY(61,13); printf(""); GotoXY(61,13); scanf("%d",&stuAry[i].age); } fflush(stdin); ClDispInfo(); GotoXY(25,19); printf(""); GotoXY(75,13); scanf("%f",&stuAry[i].hight); while(stuAry[i].hight<0||stuAry[i].hight>3) { DispErrorInfo(); GotoXY(25,19); printf("身高应在0-3米之内"); GotoXY(75,13); printf(""); GotoXY(75,13); scanf("%f",&stuAry[i].hight); } fflush(stdin); Ary[i]=stuAry[i]; b++; //fwrite(&Ary[i],sizeof(structstuType),1,fp); //fclose(fp); } //count++; } //fclose(fp); count=count-1; fp=fopen("stu.dat","w"); for(i=0;i { fwrite(&Ary[i],sizeof(structstuType),1,fp); } fclose(fp); if(b<=0) { GotoXY(37,8); printf("没有此项"); } 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; } } } /************排序***********/ voidSortAry() { inti=0; inta,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("Thefile\"stu.dat\"isopenedfiled! "); exit (1); } while(! feof(fp)) { fread(&Ary[i],sizeof(structstuType),1,fp); i++; } i=i-1; for(a=0;a { for(b=a+1;b { if(Ary[a].age>=Ary[b].age) { c=Ary[a].age; Ary[a].age=Ary[b].age; Ary[b].age=c; } } } for(a=0;a { GotoXY(5,7+a); printf("%s",Ary[a].name); fflush(stdin); GotoXY(18,7+a); printf("%s",Ary[a].gender); fflush(stdin); GotoXY(29,7+a); printf("%s",Ary[a].phone); fflush(stdin); GotoXY(47,7+a); printf("%d",Ary[a].age); fflush(stdin); GotoXY(55,7+a); printf("%1.2f",Ary[a].hight); fflush(stdin); } GotoXY(10,21); printf("信息显示完毕,按Esc键返回上一层...."); if(getche()==27) { test=! test; } } /***********统计模块***********/ voidstatitics() { inti=0; intcount=0; inta; floatage,hight,sum2=0,sum1=0; system("cls"); GotoXY(15,5); printf("信息统计"); GotoXY(5,6); printf("==============================="); fp=fopen("stu.dat","r"); if(fp==NULL) { printf("Thefile\"stu.dat\"isopenedfiled! "); exit (1); } while(! feof(fp)) { fread(&Ary[i],sizeof(structstuType),1,fp); i++; count++; } fclose(fp); count=count-1; GotoXY(5,7); printf("班级总人数: %d",count); for(a=0;a { sum1+=Ary[a].age; sum2+=Ary[a].hight; } age=float(sum1)/count; hight=sum2/count; GotoXY(5,8); printf("班级平均年龄是: %1.2f",age); GotoXY(5,9); printf("班级平均身高(m): %1.2f",hight); GotoXY(5,11); printf("信息显示完毕,按Esc键返回上一层..."); if(getche()==27) { test=! test; } } /************输入模块显示信息****************/ voidScanfInfo(stuTypestu[]){ inti=0; GotoXY(8,13); scanf("%s",stu[i].name); fflush(stdin); GotoXY(26,13); scanf("%s",stu[i].gender); fflush(stdin); GotoXY(42,13); scanf("%s",stu[i].phone); while(strlen(stu[i].phone)! =11) { DispErrorInfo(); GotoXY(25,19); printf("手机号码输入错误,应为11为数字! "); GotoXY(42,13); printf(""); GotoXY(42,13); scanf("%s",&stu[i].phone); } fflush(stdin); ClDispInfo(); GotoXY(25,19); printf(""); GotoXY(61,13); scanf("%d",&stu[i].age); while(stu[i].age<0||stu[i].age>120) { DispErrorInfo(); GotoXY(25,19); printf("年龄输入应在0-120之内"); GotoXY(61,13); printf(""); GotoXY(61,13); scanf("%d",&stu[i].age); } fflush(stdin); ClDispInfo(); GotoXY(25,19); printf(""); GotoXY(75,13); scanf("%f",&stu[i].hight); while(stu[i].hight<0||stu[i].hight>3) { DispErrorInfo(); GotoXY(25,19); printf("身高应在0-3米之内"); GotoXY(75,13); printf(""); GotoXY(75,13); scanf("%f",&stu[i].hight); } fflush(stdin); ClDispInfo(); GotoXY(25,19); printf(""); //GotoXY(35,15); //scanf("%s",&ch); //} } /**************清除显示信息***************/ voidClearInfo() { GotoXY(8,13); printf(""); GotoXY(26,13); printf(""); GotoXY(42,13); printf(""); GotoXY(61,13); printf(""); GotoXY(75,13); printf(""); GotoXY(35,15); printf(""); } /*********************//* voidClearInfo1() { GotoXY(40,13)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 学生 信息管理 系统