自己编的一个成绩管理系统,大家分享一下
程序代码:#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#define FAIL 60 //定义及格线
#define PERFECT 85 //优秀分数线
//自定义函数
void quit();
float getf();
int getnum();
char *getc();
void gettime();
void creat() ;
void insert() ;
void dele();
void rank();
void quit();
void write();
int read() ;
void print();
void submenue();
void search();
void rank_choice();
void rank_total();
void rank_num();
void rank_politics();
void rank_AMaths();
void rank_math();
void rank_English();
void rank_profession();
void search_personnal();
void search_name();
void search_num();
void search_fail();
void search_perfect();
typedef struct per
{
int num; //学号
char name[20]; //姓名
float AMaths,politics,English,profession,ave,total; /*AMaths(高数) politics(政治) English(英语) profession(专业课) */
struct per *next;
}stu;
stu *head=NULL; //头指针初始化
int node=0; //结点个数初始化
void main()
{
while(1)
{
submenue();
Sleep(1000);
system("cls");
}
getch();
}
/*函数:getf() 功能:返回一个浮点数值*/
float getf()
{
float num;
while(scanf("%f",&num)!=1)
{
while(getchar()!='\n')
continue;
printf("error input again\n");
}
return(num);
}
/*函数:getnum() 功能:返回一个整形数值*/
int getnum()
{
int num;
while(scanf("%d",&num)!=1)
{
while(getchar()!='\n')
continue;
printf("error input again\n");
}
return(num);
}
/*函数:getc() 功能:返回一个"y"或者"n"的字符串*/
char *getc()
{
char c[10];
scanf("%s",c);
while((strcmp(c,"y")!=0)&&strcmp(c,"n")!=0)
{
printf("it be able to identify 'y'or'n',input again:");
gets(c);
}
return(c);
}
/*函数:gettime() 功能:返回当前日期*/
void gettime()
{
char str[20];
time_t t;
struct tm *tp;
time(&t);
tp=localtime(&t);
strftime(str,20,"%Y年%m月%d日",tp);
printf("%s",str);
}
/*函数:creat() 功能:创建链表*/
void creat() //建立列表
{
stu *p1,*p2;
char *or;
if((head=p1=p2=(stu *)malloc(sizeof(stu)))==NULL)
{
printf("memery allocation failture!\n");
return;
}
strset((char *)p1,' ');
head->next=NULL;
printf("Are you sure you want creat the list?");
or=getc();
while(strcmp(or,"y")==0)
{
node++;
p1=(stu *)malloc(sizeof(stu));
strset((char *)p1,'0');
printf("input the information of the %d student :\n ",node);
printf("num : ");
p1->num=getnum();
printf("name: ");
scanf("%s",p1->name);
printf("AMaths score: ");
p1->AMaths=getf();
printf("politics score: ");
p1->politics=getf();
printf("English score: ");
p1->English=getf();
printf("profession score: ");
p1->profession=getf();
p1->total=p1->AMaths+p1->politics+p1->English+p1->profession;
p1->ave=p1->total/4;
p2->next=p1;
p1->next=NULL;
p2=p1;
printf("continue or not?\n");
or=getc();
}
getch();
}
/*函数:dele() 功能:按编号删除某一结点*/
void dele()
{
int num;
stu *p1,*p2;
if(head==NULL)
{
printf("链表未建立!\n");
return;
}
p1=head->next;
p2=head;
printf("the deleted num:");
num=getnum();
if(p1==NULL)
{
printf("list null,can't delete \n");
return;
}
while(p1!=NULL&&p1->num!=num)
{
p2=p1;
p1=p1->next;
}
if(p1==NULL)
{
printf("sorry cannot find it\n");
return;
}
else
p2->next=p1->next;
node--;
print();
}
/*函数:insert() 功能:插入节点*/
void insert() //插入
{
stu *p1,*p2,*p0;
if(head==NULL)
{
printf("列表未建立!\n");
return;
}
p2=head;
p1=head->next;
p0=(stu *)malloc(sizeof(stu));
printf("the information of the insert node:\n");
printf("num : ");
p0->num=getnum();
printf("name: ");
scanf("%s",p0->name);
printf("AMaths score: ");
p0->AMaths=getf();
printf("politics score: ");
p0->politics=getf();
printf("English score: ");
p0->English=getf();
printf("profession score: ");
p0->profession=getf();
p0->total=p0->AMaths+p0->English+p0->politics+p1->profession;
p0->ave=p0->total/4;
if(p1==NULL)
{
p0->next=NULL;
head->next=p0;
}
else
{
while(p1!=NULL&&p1->num<p0->num)
{
p2=p1;
p1=p1->next;
}
if(p1==NULL)
{
p0->next=NULL;
p2->next=p0;
}
else
{
p2->next=p0;
p0->next=p1;
}
}
printf("插入成功!\n");
print();
}
/*函数:quit() 功能:退出并保存数据*/
void quit()
{
if(head!=NULL)
{
printf("正在保存数据.....\n");
Sleep(2000);
write();
}
}
/*函数:submenue() 功能:选择主菜单*/
void submenue()
{
char *str[]={"退出系统 ","输入学生的信息","显示学生的成绩","查询学生的成绩","删除学生的信息","插入学生的信息","对成绩进行排序","保存输入的信息","从文件读取信息"};
int i,choice;
for(i=0;i<80;i++)
printf("*");
printf("\t\t\t**欢迎进入学生成绩管理系统**\n");
for(i=0;i<80;i++)
printf("*");
printf("**\t1: 输入学生的信息\t**\t2: 显示学生的成绩\t**\n");
printf("**\t3: 查询学生的成绩\t**\t4: 删除学生的信息\t**\n");
printf("**\t5: 插入学生的信息\t**\t6: 对成绩进行排序\t**\n");
printf("**\t7: 保存输入的信息\t**\t8: 从文件读取信息 \t**\n");
printf("**\t \t0: 退出系统 \t**\n");
for(i=0;i<80;i++)
printf("*");
printf("\t *****************");
gettime();
printf("*****************\n");
printf("**请选择(0~9):");
choice=getnum();
while(choice<0&&choice>9)
{
printf("**\terror,input again:");
choice=getnum();
}
system("cls");
printf("操作%2.2d :%s\n",choice,str[choice]);
Sleep(1000);
switch(choice)
{
case 1:creat();break;
case 2:print();break;
case 3:search();break;
case 4:dele();break;
case 5:insert();break;
case 6:rank_choice();break;
case 7:write();break;
case 8:read();break;
case 0: {quit();Sleep(1000);exit(0);};break;
}
}
/* 函数:print() 功能:打印列表 */
void print()
{
stu *p;
if(head==NULL)
{
printf("链表未建立!\n");
return;
}
p=head->next;
if(p==NULL)
{
printf("list null\n");
return;
}
printf(" num name AMaths politics English profession ave total\n");
while(p!=NULL)
{
printf(" %2.2d %12s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",p->num,p->name,p->AMaths,p->politics,p->English,p->profession,p->ave,p->total);
p=p->next;
}
getch();
}
/* 函数:rank_choice() 功能:排序的选择菜单 */
void rank_choice()
{
int choice;
while(1)
{
printf("排序方法(从小到大):\n\t\t**1.按学号排序. **2.按总成绩排序.\n\t\t**3.按高数成绩排序. **4.按政治成绩排序.\n\t\t**5.按英语成绩排序. **6.按专业课成绩排序.\n\t\t\t***0.返回上级菜单.***\n");
printf("\t**请选择:");
choice=getnum();
while(choice<0||choice>6)
{
printf("error!input again!\n");
choice=getnum();
}
switch(choice)
{
case 0:return;break;
case 1:rank_num();break;
case 2:rank_total();break;
case 3:rank_AMaths();break;
case 4:rank_politics();break;
case 5:rank_English();break;
case 6:rank_profession();break;
}
system("cls");
}
}
/* 函数:rank_total() 功能:按总成绩排序 */
void rank_total()
{
stu *p1,*p2,temp;
struct per *t;
if(head==NULL)
{
printf("\t链表未建立!\n");
return;
}
for(p1=head->next;p1!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->ave<=p2->ave)
{
temp=*p1;*p1=*p2;*p2=temp;
t=p1->next;p1->next=p2->next;p2->next=t;
}
printf("总成绩排序:\n");
print();
}
/* 函数:rank_num() 功能:按学号排序 */
void rank_num()
{
stu *p1,*p2,temp;
struct per *t;
if(head==NULL)
{
printf("\t链表未建立!\n");
return;
}
for(p1=head->next;p1!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->num>=p2->num)
{
temp=*p1;*p1=*p2;*p2=temp;
t=p1->next;p1->next=p2->next;p2->next=t;
}
printf("学号排序:\n");
print();
}
/* 函数:rank_politics() 功能:按政治成绩排序 */
void rank_politics()
{
stu *p1,*p2,temp;
struct per *t;
if(head==NULL)
{
printf("\t链表未建立!\n");
return;
}
for(p1=head->next;p1!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->politics<=p2->politics)
{
temp=*p1;*p1=*p2;*p2=temp;
t=p1->next;p1->next=p2->next;p2->next=t;
}
printf("政治成绩排序:\n");
print();
}
/* 函数:rank_AMaths() 功能:按高数成绩排序 */
void rank_AMaths()
{
stu *p1,*p2,temp;
struct per *t;
if(head==NULL)
{
printf("\t链表未建立!\n");
return;
}
for(p1=head->next;p1!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->AMaths<=p2->AMaths)
{
temp=*p1;*p1=*p2;*p2=temp;
t=p1->next;p1->next=p2->next;p2->next=t;
}
printf("高数成绩排序:\n");
print();
}
/* 函数:rank_English() 功能:按英语成绩排序 */
void rank_English()
{
stu *p1,*p2,temp;
struct per *t;
if(head==NULL)
{
printf("\t链表未建立!\n");
return;
}
for(p1=head->next;p1!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->English<=p2->English)
{
temp=*p1;*p1=*p2;*p2=temp;
t=p1->next;p1->next=p2->next;p2->next=t;
}
printf("英语成绩排序:\n");
print();
}
/* 函数:rank_profession() 功能:按专业课成绩排序 */
void rank_profession()
{
stu *p1,*p2,temp;
struct per *t;
if(head==NULL)
{
printf("\t链表未建立!\n");
return;
}
for(p1=head->next;p1!=NULL;p1=p1->next)
for(p2=p1->next;p2!=NULL;p2=p2->next)
if(p1->profession<=p2->profession)
{
temp=*p1;*p1=*p2;*p2=temp;
t=p1->next;p1->next=p2->next;p2->next=t;
}
printf("专业课成绩排序:\n");
print();
}
/* 函数:output() 功能:打印p0中的内容 */
void output(stu *p0)
{
printf(" %2.2d %12s %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n",p0->num,p0->name,p0->AMaths,p0->politics,p0->English,p0->profession,p0->ave,p0->total);
}
/*函数: search() 功能:查找操作主菜单 */
void search()
{
int choice;
stu *p;
if(head==NULL)
{
printf("链表未建立!\n");
return;
}
while(1)
{
system("cls");
printf("查询操作: \n");
printf("\t**1.查找个人信息\t**2.查找不及格信息\n\t**3.查找优秀信息\t**0.返回上级菜单\n");
printf("\t**请选择:");
choice=getnum();
while(choice<0||choice>3)
{
printf(" \terro!input again!\n");
choice=getnum();
}
switch(choice)
{
case 0:{return;};break;
case 1:search_personnal();break;
case 2:search_fail();break;
case 3:search_perfect();break;
}
}
}
/* 函数 :search_personnal() 功能:个人信息查找选择菜单*/
void search_personnal()
{
int choice;
while(1)
{
system("cls");
printf("个人信息查找操作\n\t**1.姓名查找\n\t**2.学号查找\n\t0.返回上一级\n");
printf("\t**请选择:");
choice=getnum();
while(choice<0||choice>2)
{
printf("\terror!input again:");
choice=getnum();
}
switch(choice)
{
case 0:{Sleep(2000);return;}break;
case 1:search_name();break;
case 2:search_num();break;
}
}
}
/*函数:search_name() 功能:按姓名查找*/
void search_name()
{
char name[20];
stu *p;
p=head;
if(p->next==NULL)
{
printf("list null,can't perform the operation \n");
return;
}
printf("the name you look for:");
scanf("%s",name);
while(p!=NULL&&strcmp(p->name,name)!=0)
p=p->next;
if(p==NULL)
{
printf("cannot find it\n");
return;
}
else
{
system("cls");
printf("姓名查找结果:\n");
printf(" num name AMaths politics English profession ave total\n");
output(p);
getch();
}
}
/*函数:search_num() 功能:按学号查找*/
void search_num()
{
int num;
stu *p;
p=head;
if(p->next==NULL)
{
printf("list null,can't perform the operation \n");
return;
}
printf("the num you look for:");
num=getnum();
while(p!=NULL&&p->num!=num)
p=p->next;
if(p==NULL)
{
printf("cannot find it\n");
return;
}
else
{
system("cls");
printf("学号查找结果:\n");
printf(" num name AMaths politics English profession ave total\n");
output(p);
getch();
}
}
/*函数:search_fail() 功能:查找不及格人员信息*/
void search_fail()
{
stu *p;
p=head;
int fail_num=0;
if(p->next==NULL)
{
printf("list null,can't perform the operation\n");
return;
}
system("cls");
printf("不及格查找结果:\n");
printf(" num name AMaths politics English profession ave total\n");
p=p->next;
while(p!=NULL)
{
if(p->AMaths<FAIL||p->English<FAIL||p->politics<FAIL||p->profession<FAIL)
{
fail_num++;
output(p);
}
p=p->next;
}
printf("不及格人数: %2.2d",fail_num);
if(fail_num==0)
printf("perfect,noboday have been failed in the exam!\n");
getch();
}
/*函数:search_perfect() 功能:查找优秀人员信息*/
void search_perfect()
{
stu *p;
p=head;
int per_num=0;
if(p->next==NULL)
{
printf("list null,can't perform the operation\n");
return;
}
system("cls");
printf("优秀查找结果:\n");
printf(" num name AMaths politics English profession ave total\n");
p=p->next;
while(p!=NULL)
{
if((p->AMaths>PERFECT&&p->English>PERFECT&&p->politics>PERFECT&&p->profession>PERFECT)||p->total>PERFECT*4)
{
per_num++;
output(p);
}
p=p->next;
}
printf("优秀人数:%2.2d\n",per_num);
if(per_num==0)
printf("sorry,noboday was outstanding been in the exam!\n");
getch();
}
/*函数:write() 功能:保存数据到文件*/
void write()
{
FILE *fp;
stu *p;
if(head==NULL)
{
printf("链表未建立!\n");
return;
}
p=head->next;
if(p==NULL)
{
printf("list null\n");
return;
}
if((fp=fopen("d:\\xinjian.txt","w"))==NULL)
{
printf("cannot open the file\n");
return;
}
while(p!=NULL)
{
fwrite(p,sizeof(stu),1,fp);
p=p->next;
}
fcloseall();
Sleep(1000);
printf("保存成功!\n");
return;
}
/*函数:read() 功能:从文件中读取数据*/
int read()
{
FILE *fp;
stu *p1,*p2;
int num;
p1=p2=head=(stu *)malloc(sizeof(stu));
if(p1==NULL)
{
printf("memery allocation failture\n");
return 0;
}
p1->next=NULL;
if((fp=fopen("d:\\xinjian.txt","r+"))==NULL)
{
printf("cannot open the file\n");
return 0;
}
fseek(fp,0,2);
num=ftell(fp)/sizeof(stu);
rewind(fp);
while(num)
{
p1=(stu *)malloc(sizeof(stu));
fread(p1,sizeof(stu),1,fp);
p1->next=NULL;
p2->next=p1;
p2=p1;
num--;
}
fcloseall();
Sleep(1000);
printf("读取成功!\n");
printf("读取项目如下:\n");
Sleep(1000);
print();
return 0;
}








顶下……

呵呵~
我发现函数都没有参数

