/*头文件*/
#include <stdio.h>
#include<dos.h>
#include<stdlib.h> /*其它说明*/
#include<string.h> /*字符串函数*/
#include<mem.h> /*内存操作函数*/
#include<ctype.h> /*字符操作函数*/
#include<alloc.h> /*动态地址分配函数*/
#define LEN sizeof(STUDENT)
typedef struct stu /*定义结构体数组用于缓存数据*/
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;
/*函数原型*/
STUDENT *init(); /*初始化函数*/
int menu_select(); /*菜单函数*/
STUDENT *create(); /*创建链表*/
void print(STUDENT *head); /* 显示全部记录*/
void search(STUDENT *head); /*查找记录*/
STUDENT *delete(STUDENT *head); /*删除记录*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *new); /*插入记录*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*读文件*/
/*主函数界面*/
main()
{STUDENT *head,new;
head=init(); /*链表初始化,使head的值为NULL*/
for(;;) /*循环无限次*/
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,&new);break; /*&new表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜单返回值为9则程序结束*/
}
}
}
/*初始化函数*/
STUDENT *init()
{
return NULL; /*返回空指针*/
}
/*菜单选择函数*/
menu_select()
{int n;
struct date d; /*定义时间结构体*/
getdate(&d); /*读取系统日期并把它放到结构体d中*/
printf("press any key to enter the menu......"); /*按任一键进入主菜单*/
getch(); /*从键盘读取一个字符,但不显示于屏幕*/
clrscr(); /*清屏*/
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. Enter the record\n"); /*输入学生成绩记录*/
printf("\t\t\t2. Print the record\n"); /*显示*/
printf("\t\t\t3. Search record on name\n"); /*寻找*/
printf("\t\t\t4. Delete a record\n"); /*删除*/
printf("\t\t\t5. Sort to make new a file\n"); /*排序*/
printf("\t\t\t6. Insert record to list\n"); /*插入*/
printf("\t\t\t7. Save the file\n"); /*保存*/
printf("\t\t\t8. Load the file\n"); /*读取*/
printf("\t\t\t9. Quit\n"); /*退出*/
printf("\n\t\t Made by Hu Haihong.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day); /*显示当前系统日期*/
do{
printf("\n\t\t\tEnter your choice(1~9):");
scanf("%d",&n);
}while(n<1||n>9); /*如果选择项不在1~9之间则重输*/
return(n); /*返回选择项,主函数根据该数调用相应的函数*/
}
751com.cn
{printf("\nOut of memory."); /*输出内存溢出*/
return (head); /*返回头指针,下同*/
}
printf("Enter the num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break; /*如果学号首字符为0则结束输入*/
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3); /*提示开始输入成绩*/
s=0; /*计算每个学生的总分,初值为0*/
for(i=0;i<3;i++) /*3门课程循环3次*/
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100) /*确保成绩在0~100之间*/
printf("Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i]; /*累加各门成绩*/
}
p->sum=s; /*将总分保存*/
p->average=(float)s/3; /*先用强制类型转换将s转换成float型,再求平均值*/
p->order=0; /*未排序前此值为0*/
p->next=head; /*将头结点做为新输入结点的后继结点*/
head=p; /*新输入结点为新的头结点*/
}
return(head);
}
/* 显示全部记录函数*/