1.c?语言学语言源代???ѧ??????Դ??
2.ç¨cè¯è¨ç¼åä¸ä¸ªå¦ç管çç³»ç»
3.学籍管理系统学生信息录入模块c语言程序
4.用c语言编写一个学生学籍管理系统
5.C语言学生信息管理系统程序相映论文!!
6.cè¯è¨è¯¾ç¨è®¾è®¡å¦ç±ç®¡çç³»ç»
c????ѧ??????Դ??
c语言问题急求答案①输入5个学生的数据信息,包括学生的籍管学号,姓名,理源数学、码c码英语和语文三门课程的学籍系统游戏源码泄露成绩并统计平均成绩;②系统中学生数据的排列顺序,初始时是管理钻石趋势波段幅图源码按照输入顺序排列的;根据使用者的选择,可以按照学号由低向高排序,语言学语言源代也可以按照平均成绩由高向低排序;求大神
ç¨cè¯è¨ç¼åä¸ä¸ªå¦ç管çç³»ç»
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
class student
{
protected:
int number;
char name[];
char sex[6];
char place[];
char nation[6];
char birth[];
char party[];
char id[];
double score[3];
public:
student *next;
student(){ }
~student(){ }
char* getname(){ return name; }
int getnumber(){ return number;}
double getscore(int i) { return score[3];}
float getg(){ return (score[0]+score[1]+score[2]); }
void input()
{
int e=1;
cout<<"\t\t\tææ示è¾å ¥:"<<endl;
cout<<"\t\tè¾å ¥ç¼å·: ";
cin>>number;
cout<<"\t\tè¾å ¥å§å: ";
cin>>name;
do
{
cout<<"\t\tè¾å ¥æ§å«: ";
cin>>sex;
if(strcmp(sex,籍管"ç·")==0 || strcmp(sex,"女")==0)
{
cout<<"\t\tè¾å ¥ç±è´¯: ";
cin>>place;
cout<<"\t\tè¾å ¥æ°æ: ";
cin>>nation;
cout<<"\t\tè¾å ¥çæ¥: ";
cin>>birth;
cout<<"\t\tè¾å ¥æ¿æ²»é¢è²: ";
cin>>party;
cout<<"\t\tè¾å ¥èº«ä»½è¯å·: ";
cin>>id;
cout<<"\t\tè¾å ¥æ°å¦åæ°: ";
cin>>score[0];
cout<<"\t\tè¾å ¥è±è¯åæ°: ";
cin>>score[1];
cout<<"\t\tè¾å ¥è®¡ç®æºåæ°: ";
cin>>score[2];
e=0;
}
else
{
cout<<"\t\t\tæ æ¤ç±»åæ§å«!éæ°è¾å ¥!"<<endl;
e=1;
}
}while(e);
return ;
}
void input(ifstream & is)
{
is>>number>>name>>sex>>place>>nation>>birth>>party>>id
>>score[0]>>score[1]>>score[2];
is.get();
}
void output()
{
cout<<"å¦çåºæ¬ä¿¡æ¯å¦ä¸:"<<endl;
cout<<"ç¼å·:"<<number
<<" å§å:"<<name
<<" æ§å«:"<<sex
<<" ç±è´¯:"<<place
<<" æ°æ:"<<nation
<<" çæ¥:"<<birth
<<" æ¿æ²»é¢è²:"<<party<<endl
<<"身份è¯å·:"<<id
<<" æ°å¦:"<<score[0]
<<" è±è¯:"<<score[1]
<<" 计ç®æº:"<<score[2]
<<" æ»å:"<<getg()<<endl<<endl;
}
void output(ofstream & os)
{
os<<setw(6)<<number
<<setw()<<name
<<setw(6)<<sex
<<setw()<<place
<<setw(6)<<nation
<<setw()<<birth
<<setw()<<party
<<setw()<<id
<<setw(6)<<score[0]
<<setw(6)<<score[1]
<<setw(6)<<score[2]<<endl;
}
};
class school
{
public:
school(){ head=new student; head->next=NULL; key=0; }
~school(){ delete head; }
void input();
void mend();
void del();
int find(student **p,int num,char *pn="^");
void found();
void show();
void count();
void save();
void begin();
void clear();
char mainmenu();
int getkey(){ return key;}
void setkey(int k){ key=k; }
private:
student *head;
int key;
};
//å½å ¥å½æ°
void school::input()
{
student *p,*p2=NULL;
p=head;
int n;
while(p->next)
p=p->next;
while(n)
{
p2=new student;
p2->input();
p->next=p2;
p2->next=NULL;
p=p->next;
school::setkey(1);
cout<<"\t\t\tæ1继ç»,æ0è¿å : ";
cin>>n;
}
}
//åæ¥æ¾å½æ°
int school::find(student **p1,int num,char *pn)
{
student *p;
p=head;
while(p->next)
{
(*p1)=p;
if( (p->next)->getnumber()==num||!strcmp( (p->next)->getname(),pn ) )
return 1;
p=p->next;
}
return 0;
}
//æ¥æ¾å½æ°
void school::found()
{
student *p;
int num=-1,n=9;
char name[]="^";
do
{
cout<<"\t\t1:æç¼å·æ¥æ¾,2:æå§åæ¥æ¾: ";
cin>>n;
}while(n<1||n>2);
if(n==1)
{
cout<<"\t\t\tè¾å ¥ç¼å·: ";
cin>>num;
}
if(n==2)
{
cout<<"\t\t\tè¾å ¥å§å: ";
cin>>name;
}
if(!find(&p,num,name) )
{
cout<<"\t\tæ¾ä¸å°ä½ è¦æ¥æ¾çå 容!"<<endl;
return;
}
(p->next)->output();
}
//å é¤å½æ°
void school::del()
{
student *p,*p2;
int num;
cout<<"\t\t\tè¾å ¥ç¼å·: ";
cin>>num;
if( !find(&p,num,"^") )
{
cout<<"\t\tæ¾ä¸å°ä½ è¦å é¤çå 容!"<<endl;
return;
}
(p->next)->output();
p2=p->next;
p->next=p2->next;
delete p2;
school::setkey(1);
}
//æ¾ç¤ºå½æ°
void school::show()
{
student *p;
p=head;
while(p->next)
{
(p->next)->output();
p=p->next;
}
}
//ä¿®æ¹å½æ°
void school::mend()
{
student *p;
int num=-1,n;
char name[]="^";
do
{
cout<<"\t\t1:æç¼å·ä¿®æ¹,2:æå§åä¿®æ¹: ";
cin>>n;
}while(n<1||n>2);
if(n==1)
{
cout<<"\t\t\tè¾å ¥ç¼å·: ";
cin>>num;
}
if(n==2)
{
cout<<"\t\t\tè¾å ¥å§å: ";
cin>>name;
}
if( !find(&p,num,name) )
{
cout<<"\t\tæ¾ä¸å°ä½ è¦ä¿®æ¹çå 容!"<<endl;
return;
}
(p->next)->output();
(p->next)->input();
school::setkey(1);
}
//ä¿åå½æ°
void school::save()
{
student *p;
p=head;
ofstream os("student.txt",ios::out);
if (school::getkey()==1)
{
while(p->next)
{
(p->next)->output(os);
p=p->next;
}
}
cout<<"\t\t\tæ件已ä¿å! "<<endl;
school::setkey(0);
}
//åå§åå½æ°
void school::begin()
{
student *p,*p2;
p=head;
clear();
long t;
ifstream is("student.txt",ios::in);
if(!is)
{
ofstream os("student.txt",ios::out);
os.close();
return ;
}
int num=-1;
while(1)
{
num=-1;
t=is.tellg();
is>>num;
is.seekg(t);
if(num<0)
{
is.close();
return;
}
p2=new student;
p2->input(is);
p->next=p2;
p2->next=NULL;
p=p->next;
}
}
//æ¸ ç©ºå½æ°
void school::clear()
{
student *p,*p2;
p=head->next;
while( p )
{
p2=p;
p=p->next;
delete p2;
}
}
//ç»è®¡å½æ°
void school::count()
{
student *p;
p=head;
int n=0;
double g[3]={ 0,0,0};
float j[3]={ 0,0,0};
while(p->next)
{
p=p->next;
n++;
for(int i=0;i<3;i++)
{
g[++i]=g[i]+( p->getscore(i) );
(p->getscore(i) )>=? j[i++] : 0 ;
}
}
cout<<"\t\t\b\b\b\bæ°å¦æ»å:"<<g[0]<<" å¹³åå:"<<g[0]/n
<<" åæ ¼ç:"<<j[0]/n<<endl<<"\t\t\b\b\b\bè±è¯æ»å:"<<g[1]
<<" å¹³åå:"<<g[1]/n<<" åæ ¼ç:"<<j[1]/n<<endl
<<"\t\t\b\b\b\b计ç®æºæ»å: "<<g[2]<<" å¹³åå: "<<g[2]/n
<<" åæ ¼ç:"<<j[2]/n<<endl;
}
//主éèåå½æ°
char school::mainmenu()
{
char n[6];
cout<<"\n\n ââââ欢è¿è¿å ¥é«æ ¡å¦ç±ç®¡çç³»ç»ââââ"<<endl<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * 1: å½å ¥å¦çä¿¡æ¯ * *"<<endl
<<" * * 2: æ¾ç¤ºå¦çä¿¡æ¯ * *"<<endl
<<" * * 3: æ¥æ¾å¦çä¿¡æ¯ * *"<<endl
<<" * * 4: å é¤å¦çä¿¡æ¯ * *"<<endl
<<" * * 5: ä¿®æ¹å¦çä¿¡æ¯ * *"<<endl
<<" * * 6: ç»è®¡å¦çæ绩 * *"<<endl
<<" * * 7: ä¿åå¦çä¿¡æ¯ * *"<<endl
<<" * * 0: éåºç³»ç» * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" 请éæ©:";
cin>>n;
return n[0];
}
//主å½æ°
void main()
{
school pp;
int k=1;
char n;
pp.begin();
while(k==1)
{
n=pp.mainmenu();
switch(n)
{
case '1':pp.input(); break;
case '2':pp.show(); break;
case '3':pp.found(); break;
case '4':pp.del(); break;
case '5':pp.mend(); break;
case '6':pp.count(); break;
case '7':pp.save(); break;
case '0':
if(pp.getkey()==1)
{
cout<<"\t\t\tæ¯å¦ä¿å? 1 : ä¿å 0:ä¸ä¿å : ";
cin>>k;
if(k==1)
pp.save();
}
pp.clear();
k=0;
break;
}
}
}
学籍管理系统学生信息录入模块c语言程序
给个参考你:/*编制一个学生成绩管理系统,每个学生信息包括:学号、理源姓名、码c码C语言、学籍系统高数和英语成绩。管理具体功能:(1)创建信息链表并以磁盘文件保存;(2)读取磁盘文件并显示输出所有学生的语言学语言源代网站设计大屏首页源码成绩;(3)按学号或姓名查询成绩;(4)添加成绩记录;(5)修改指定姓名或学号的学生的成绩并可存盘;(6)显示输出分以下、~、籍管~、理源分以上各分数段的学生信息。以C语言成绩为例*/#include#include#include#include#defineNtypedefstruct{ charname[];intnum;floatc;floatmath;floatenglish;floataver;}stu;//菜单voidmenu()/*便于操作员使用*/{ /*清屏*/system("cls");printf("学生平时成绩管理\n");printf("=======================\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("0.退出\n");printf("=======================\n");printf("请选择相应的白菜app前端源码二开功能:");}//成绩录入voidinput(){ FILE*fp;stuxs;/*定义一个结构体变量来装从文件中读出来的数据*/if((fp=fopen("student.dat","ab"))==NULL){ printf("can'topenfile!\n");exit(0);}printf("\n录入格式:姓名学号C语言高数英语当输入姓名为ps结束录入\n");while(1)/*中间加油break,可使循环中断*/{ scanf("%s",xs.name);if(strcmp(xs.name,"ps")==0)break;/*判断姓名是否为ps,用字符串判断*/scanf("%d%f%f%f",&xs.num,&xs.c,&xs.math,&xs.english);xs.aver=0;/*给平均分变量赋初值*/fwrite(&xs,sizeof(stu),1,fp);//将成绩信息写入文件}fclose(fp);}//计算平均分voidsum(){ inti=0,n;stuxs[N];FILE*fp;if((fp=fopen("student.dat","rb+"))==NULL){ printf("can'topenfile!\n");exit(0);}while(!feof(fp))/*文件读入内存,读取指针未到文件尾时返回值为0,读到尾时返回值为1,希腊神话app源码开发加!取反后,结束即为0*/{ fread(&xs[i],sizeof(stu),1,fp);/*读入结构体变量*/if(feof(fp))break;/*上面while循环那个会多读一次因为读到尾时那个0还没返回,这里判断如果以读到文件尾,则直接停止,避免重复输入*/xs[i].aver=(xs[i].c+xs[i].math+xs[i].english)/3;i++;}n=i;/*把i的末尾值给n,用于下面循环写入*/i=0;fclose(fp);if((fp=fopen("student.dat","wb"))==NULL){ printf("can'topenfile!\n");exit(0);}while(i=0)/*k的位置要位于数组范围之内*/{ //插入for(j=lenth-1;j>=k;j--)xs[j+1]=xs[j];/*一开始j是最大的,往后移一个这样移动避免数据被覆盖*//*循环是只循环这一句的*/xs[k]=s;/*将输入的学生信息加入这个k位置*/lenth++;/*长度+1*///写回if((fp=fopen("student.dat","wb"))==NULL){ printf("不能建立文件!!\n");exit(0);}for(i=0;i=&&s[i].c=&&s[i].c=){ p4[m++]=&s[i++];continue;}}printf("不及格:姓名学号C语言\n");for(n=0;nname,p1[n]->num,p1[n]->c);}printf("-:姓名学号C语言\n");for(p=0;pname,p2[p]->num,p2[p]->c);}printf("-:姓名学号C语言\n");for(q=0;qname,p3[q]->num,p3[q]->c);}printf("以上:姓名学号C语言\n");for(r=0;rname,p4[r]->num,p4[r]->c);}fclose(fp);getch();}//删除:输入学生姓名,若该学生存在,则删除,并显示删除后余下的学生成绩信息voiddele(){ stuxs[N];FILE*fp;charname[];inti=0,len,k=-1/*k=0)/*k>0说明找到删除学生位置*/{ if((fp=fopen("student.dat","wb+"))==NULL){ printf("can'topenfile!\n");exit(0);}for(i=0;i
用c语言编写一个学生学籍管理系统
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
class student
{
protected:
int number;
char name[];
char sex[6];
char place[];
char nation[6];
char birth[];
char party[];
char id[];
double score[3];
public:
student *next;
student(){ }
~student(){ }
char* getname(){ return name; }
int getnumber(){ return number;}
double getscore(int i) { return score[3];}
float getg(){ return (score[0]+score[1]+score[2]); }
void input()
{
int e=1;
cout<<"\t\t\t按提示输入:"<<endl;
cout<<"\t\t输入编号: ";
cin>>number;
cout<<"\t\t输入姓名: ";
cin>>name;
do
{
cout<<"\t\t输入性别: ";
cin>>sex;
if(strcmp(sex,"男")==0 || strcmp(sex,"女")==0)
{
cout<<"\t\t输入籍贯: ";
cin>>place;
cout<<"\t\t输入民族: ";
cin>>nation;
cout<<"\t\t输入生日: ";
cin>>birth;
cout<<"\t\t输入政治面貌: ";
cin>>party;
cout<<"\t\t输入身份证号: ";
cin>>id;
cout<<"\t\t输入数学分数: ";
cin>>score[0];
cout<<"\t\t输入英语分数: ";
cin>>score[1];
cout<<"\t\t输入计算机分数: ";
cin>>score[2];
e=0;
}
else
{
cout<<"\t\t\t无此类型性别!重新输入!"<<endl;
e=1;
}
}while(e);
return ;
}
void input(ifstream & is)
{
is>>number>>name>>sex>>place>>nation>>birth>>party>>id
>>score[0]>>score[1]>>score[2];
is.get();
}
void output()
{
cout<<"学生基本信息如下:"<<endl;
cout<<"编号:"<<number
<<" 姓名:"<<name
<<" 性别:"<<sex
<<" 籍贯:"<<place
<<" 民族:"<<nation
<<" 生日:"<<birth
<<" 政治面貌:"<<party<<endl
<<"身份证号:"<<id
<<" 数学:"<<score[0]
<<" 英语:"<<score[1]
<<" 计算机:"<<score[2]
<<" 总分:"<<getg()<<endl<<endl;
}
void output(ofstream & os)
{
os<<setw(6)<<number
<<setw()<<name
<<setw(6)<<sex
<<setw()<<place
<<setw(6)<<nation
<<setw()<<birth
<<setw()<<party
<<setw()<<id
<<setw(6)<<score[0]
<<setw(6)<<score[1]
<<setw(6)<<score[2]<<endl;
}
};
class school
{
public:
school(){ head=new student; head->next=NULL; key=0; }
~school(){ delete head; }
void input();
void mend();
void del();
int find(student **p,int num,char *pn="^");
void found();
void show();
void count();
void save();
void begin();
void clear();
char mainmenu();
int getkey(){ return key;}
void setkey(int k){ key=k; }
private:
student *head;
int key;
};
//录入函数
void school::input()
{
student *p,*p2=NULL;
p=head;
int n;
while(p->next)
p=p->next;
while(n)
{
p2=new student;
p2->input();
p->next=p2;
p2->next=NULL;
p=p->next;
school::setkey(1);
cout<<"\t\t\t按1继续,按0返回 : ";
cin>>n;
}
}
//子查找函数
int school::find(student **p1,int num,char *pn)
{
student *p;
p=head;
while(p->next)
{
(*p1)=p;
if( (p->next)->getnumber()==num||!strcmp( (p->next)->getname(),pn ) )
return 1;
p=p->next;
}
return 0;
}
//查找函数
void school::found()
{
student *p;
int num=-1,n=9;
char name[]="^";
do
{
cout<<"\t\t1:按编号查找,2:按姓名查找: ";
cin>>n;
}while(n<1||n>2);
if(n==1)
{
cout<<"\t\t\t输入编号: ";
cin>>num;
}
if(n==2)
{
cout<<"\t\t\t输入姓名: ";
cin>>name;
}
if(!find(&p,num,name) )
{
cout<<"\t\t找不到你要查找的内容!"<<endl;
return;
}
(p->next)->output();
}
//删除函数
void school::del()
{
student *p,*p2;
int num;
cout<<"\t\t\t输入编号: ";
cin>>num;
if( !find(&p,num,"^") )
{
cout<<"\t\t找不到你要删除的内容!"<<endl;
return;
}
(p->next)->output();
p2=p->next;
p->next=p2->next;
delete p2;
school::setkey(1);
}
//显示函数
void school::show()
{
student *p;
p=head;
while(p->next)
{
(p->next)->output();
p=p->next;
}
}
//修改函数
void school::mend()
{
student *p;
int num=-1,n;
char name[]="^";
do
{
cout<<"\t\t1:按编号修改,2:按姓名修改: ";
cin>>n;
}while(n<1||n>2);
if(n==1)
{
cout<<"\t\t\t输入编号: ";
cin>>num;
}
if(n==2)
{
cout<<"\t\t\t输入姓名: ";
cin>>name;
}
if( !find(&p,num,name) )
{
cout<<"\t\t找不到你要修改的内容!"<<endl;
return;
}
(p->next)->output();
(p->next)->input();
school::setkey(1);
}
//保存函数
void school::save()
{
student *p;
p=head;
ofstream os("student.txt",ios::out);
if (school::getkey()==1)
{
while(p->next)
{
(p->next)->output(os);
p=p->next;
}
}
cout<<"\t\t\t文件已保存! "<<endl;
school::setkey(0);
}
//初始化函数
void school::begin()
{
student *p,*p2;
p=head;
clear();
long t;
ifstream is("student.txt",ios::in);
if(!is)
{
ofstream os("student.txt",ios::out);
os.close();
return ;
}
int num=-1;
while(1)
{
num=-1;
t=is.tellg();
is>>num;
is.seekg(t);
if(num<0)
{
is.close();
return;
}
p2=new student;
p2->input(is);
p->next=p2;
p2->next=NULL;
p=p->next;
}
}
//清空函数
void school::clear()
{
student *p,*p2;
p=head->next;
while( p )
{
p2=p;
p=p->next;
delete p2;
}
}
//统计函数
void school::count()
{
student *p;
p=head;
int n=0;
double g[3]={ 0,0,0};
float j[3]={ 0,0,0};
while(p->next)
{
p=p->next;
n++;
for(int i=0;i<3;i++)
{
g[++i]=g[i]+( p->getscore(i) );
(p->getscore(i) )>=? j[i++] : 0 ;
}
}
cout<<"\t\t\b\b\b\b数学总分:"<<g[0]<<" 平均分:"<<g[0]/n
<<" 及格率:"<<j[0]/n<<endl<<"\t\t\b\b\b\b英语总分:"<<g[1]
<<" 平均分:"<<g[1]/n<<" 及格率:"<<j[1]/n<<endl
<<"\t\t\b\b\b\b计算机总分: "<<g[2]<<" 平均分: "<<g[2]/n
<<" 及格率:"<<j[2]/n<<endl;
}
//主选菜单函数
char school::mainmenu()
{
char n[6];
cout<<"\n\n ☆☆☆☆欢迎进入高校学籍管理系统☆☆☆☆"<<endl<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * 1: 录入学生信息 * *"<<endl
<<" * * 2: 显示学生信息 * *"<<endl
<<" * * 3: 查找学生信息 * *"<<endl
<<" * * 4: 删除学生信息 * *"<<endl
<<" * * 5: 修改学生信息 * *"<<endl
<<" * * 6: 统计学生成绩 * *"<<endl
<<" * * 7: 保存学生信息 * *"<<endl
<<" * * 0: 退出系统 * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * *"<<endl
<<" 请选择:";
cin>>n;
return n[0];
}
//主函数
void main()
{
school pp;
int k=1;
char n;
pp.begin();
while(k==1)
{
n=pp.mainmenu();
switch(n)
{
case '1':pp.input(); break;
case '2':pp.show(); break;
case '3':pp.found(); break;
case '4':pp.del(); break;
case '5':pp.mend(); break;
case '6':pp.count(); break;
case '7':pp.save(); break;
case '0':
if(pp.getkey()==1)
{
cout<<"\t\t\t是否保存? 1 : 保存 0:不保存 : ";
cin>>k;
if(k==1)
pp.save();
}
pp.clear();
k=0;
break;
}
}
}
C语言学生信息管理系统程序相映论文!!
#ifndef H_STUDENT_HH
#define H_STUDENT_HH
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#define LEN sizeof(struct message_student) /*一个结构体数组元素的长度*/
#define numsubs 5 /*学科数目*/
typedef struct message_student /*结构体定义*/
{
char number[6];
char name[];
char sex[4];
float subject[numsubs];
float score;
float average;
int index;
}student;
extern int numstus; /*学生数目*/
extern student *pointer; /*指向结构体数组*/
extern int lens;
int menu_select(); /*函数声明*/
int openfile(student stu[]);
int findrecord(student stud[]);
int writetotext(student stud[]);
void welcome();
void display1();
void showtable();
void sort(student stu[]);
void deleterecord(student stu[],int i);
void addrecord(student stud[]);
void display(student stud[],int n1,int n2);
void amendrecord(student stud[]);
void count(student stud[]);
void sortnum(student stud[]);
void sortnum2(student stud[]);
void sortname(student stud[]);
void sortname2(student stud[]);
void sortcount(student stud[]);
void sortcount2(student stud[]);
void statistic(student stud[]);
void display1();
#endif
//#include "head.h"
int menu_select()
{
char c;
printf("\n\n");
printf(" | 1. 增加学生记录 5.统计信息 |\n");
printf(" | 2. 查询学生记录 6.打开文件 |\n");
printf(" | 3. 修改学生记录 7.保存文件 |\n");
printf(" | 4. 学生纪录排序 8.显示记录 |\n");
printf(" | 0.退出系统 |\n");
printf("\n\n");
printf("请选择(0-8):");
c=getchar();
getchar();
return (c-'0');
}
//#include "head.h"
int findrecord(student stud[]) /*查找信息*/
{
char str[2];
int i,num;
if(numstus==0)
{
printf("没有可被查找的记录\n");
return -1;
}
else
{
printf("以何种方式查找?\n1.学号\t2.姓名\t3.名次\n");
gets(str);
if(str[0]=='1') /*按学号查找*/
{
printf("请输入学号:");
gets(str);
for(i=0;i<=numstus;i++)
if(strcmp(str,stud[i].number)==0)
{
display(stud,i,i);
break;
}
else continue;
}
else if(str[0]=='2') /*按姓名查找*/
{
printf("请输入姓名:");
gets(str);
for(i=0;i<=numstus;i++)
if(strcmp(str,stud[i].name)==0)
{
display(stud,i,i);
break;
}
else continue;
}
else if(str[0]=='3') /*按名次查找*/
{
printf("请输入名次:");
scanf("%d",&num);
getchar();
for(i=0;i<=numstus;i++)
if(num==stud[i].index)
{
display(stud,i,i);
break;
}
else continue;
}
if(i>numstus)
{
printf("没有查找所要的信息。\n");
return -1;
}
return i;
}
}
//#include"head.h"
int openfile(student stu[])
{
int i=0,j;
FILE *fp;
char filename[],str[2];
if(numstus!=0)
{
printf("已经有记录存在,是否保存?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
writetotext(stu);
}
printf("请输入文件名:");
gets(filename);
numstus=0;
if((fp=fopen(filename,"rb+"))==NULL)
{
printf("无法打开该文件\n");
return(-1);
}
fscanf(fp,"%d",&numstus);
fgetc(fp);
while(i<numstus)
{
fscanf(fp,"%s",stu[i].number);
fscanf(fp,"%s",stu[i].name);
fscanf(fp,"%s",stu[i].sex);
for(j=0;j<numsubs;j++)
fscanf(fp,"%f",&stu[i].subject[j]);
fscanf(fp,"%f",&stu[i].score);
fscanf(fp,"%f",&stu[i].average);
fscanf(fp,"%d",&stu[i].index);
i++;
}
fclose(fp);
printf("文件读取成功\n");
printf("是否显示纪录?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y')
display(stu,0,numstus-1);
return(0);
}
//#include "head.h"
void sort(student stud[])
{
int i,j=0;
char str[5];
student *p;
p=stud;
if(numstus==0)
{
printf("没有可供查询的记录!");
}
while(1)
{
for(i=0;;i++)
{
printf(" 请输入查询方式:");
printf("(直接输入回车则结束查询操作)\n");
printf("1.按照学号\t");
printf("2.按照姓名\t");
printf("3.按照名次\n");
gets(str);
if(strlen(str)==0) break;
if(str[0]=='1')
{
printf("请输入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortnum2(p);
else
sortnum(p);
display(stud,0,numstus-1);
}
else if(str[0]=='2')
{
printf("请输入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortname2(p);
else
sortname(p);
display(stud,0,numstus-1);
}
else if(str[0]=='3')
{
printf("请输入排序次序:\n");
printf("1.升序排列\t");
printf("2.降序排列\n");
gets(str);
if(str[0]=='1')
sortcount2(p);
else
sortcount(p);
display(stud,0,numstus-1);
}
else printf("请输入1~3");
printf("是否退出排序?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y') break;
}
return;
}
}
void sortnum(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j+1].number,stud[j].number)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortnum2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j].number,stud[j+1].number)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortname(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j+1].name,stud[j].name)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortname2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(strcmp(stud[j].name,stud[j+1].name)>0)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortcount(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(stud[j+1].index>stud[j].index)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
void sortcount2(student stud[])
{
int i,j;
student temp;
student *p;
p=stud;
for(i=0;i<numstus;i++)
for(j=0;j<numstus-i-1;j++)
{
if(stud[j].index>stud[j+1].index)
{
temp=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=temp;
}
}
}
//#include"head.h"
void statistic(student stud[]) /*新增功能,输出统计信息*/
{
int i,j=0,k=0;
char c1,str[2];
float average[numsubs],sum=0;
if(numstus==0)
printf("没有可被查找的记录\n");
else
{
while(1)
{
printf("下面将统计考试成绩\n");
printf("请选择你要统计哪科的成绩 1.A\t2.B\t3.C\t4.D\t5.E\n");
c1=getchar();
printf("\t一共有个%d记录\n",numstus); /*总共记录数*/
switch(c1)
{
case '1':
for(i=0;i<numstus;i++) /*循环输入判断*/
{
sum+=stud[i].subject[0];
if(stud[k].subject[0]>stud[i].subject[0]) k=i;
if(stud[j].subject[0]<stud[i].subject[0]) j=i;
}
average[0]=sum/numstus;
printf("\t科目A的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[0]);
printf("\t科目A的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[0]);
printf("\t科目A的平均分是 %5.2f\n",average[0]); /*平均分*/
break;
case '2':
for(i=0;i<numstus;i++) /*循环输入判断*/
{
sum+=stud[i].subject[1];
if(stud[k].subject[1]>stud[i].subject[1]) k=i;
if(stud[j].subject[1]<stud[i].subject[1]) j=i;
}
average[1]=sum/numstus;
printf("\t科目B的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[1]);
printf("\t科目B的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[1]);
printf("\t科目B的平均分是 %5.2f\n",average[1]); /*平均分*/
break;
case '3':
for(i=0;i<numstus;i++) /*循环输入判断*/
{
sum+=stud[i].subject[2];
if(stud[k].subject[2]>stud[i].subject[2]) k=i;
if(stud[j].subject[2]<stud[i].subject[2]) j=i;
}
average[2]=sum/numstus;
printf("\t科目C的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[2]);
printf("\t科目C的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[2]);
printf("\t科目C的平均分是 %5.2f\n",average[2]); /*平均分*/
break;
case '4':
for(i=0;i<numstus;i++) /*循环输入判断*/
{
sum+=stud[i].subject[3];
if(stud[k].subject[3]>stud[i].subject[3]) k=i;
if(stud[j].subject[3]<stud[i].subject[3]) j=i;
}
average[3]=sum/numstus;
printf("\t科目D的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[3]);
printf("\t科目D的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[3]);
printf("\t科目D的平均分是 %5.2f\n",average[3]); /*平均分*/
break;
case '5':
for(i=0;i<numstus;i++) /*循环输入判断*/
{
sum+=stud[i].subject[4];
if(stud[k].subject[4]>stud[i].subject[4]) k=i;
if(stud[j].subject[4]<stud[i].subject[4]) j=i;
}
average[4]=sum/numstus;
printf("\t科目E的最高分:\n"); /*最高分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[j].number,stud[j].name,stud[j].subject[4]);
printf("\t科目E的最低分是:\n"); /*最低分*/
printf("\t\t学号:%s 姓名:%s 分数:%.2f\n",stud[k].number,stud[k].name,stud[k].subject[4]);
printf("\t科目E的平均分是 %5.2f\n",average[4]); /*平均分*/
break;
default:printf("输入错误!请输入1~5之间的数\n");
}
sum=0;
getchar();
printf("是否继续进行统计?(y/n)");
gets(str);
if(str[0]=='y'||str[0]=='Y') ;
else break;
}
}
}
int writetotext(student stud[]) /*将所有记录写入文件*/
{
int i=0,j;
FILE *fp;
char filename[];
printf("输入文件名称:");
gets(filename);
fp=fopen(filename,"w");
fprintf(fp,"%d\n",numstus);
while(i<numstus)
{
fprintf(fp,"%s %s %s ",stud[i].number,stud[i].name,stud[i].sex);
for(j=0;j<numsubs;j++)
fprintf(fp,"%f ",stud[i].subject[j]);
fprintf(fp,"%f %f %d ",stud[i].score,stud[i].average,stud[i].index);
i++;
}
fclose(fp);
printf("已成功存储!\n");
display(stud,0,numstus-1);
numstus=0;
return 0;
}
void welcome()
{
printf("\t