木有雨啊
第一页/* 源程序*//**********************//******头文件(.h)***********/#include "" /*I/O函数*/#include "" /*其它说明*/#include "" /*字符串函数*/#include "" /*屏幕操作函数*/#include "" /*内存操作函数*/#include "" /*字符操作函数*/#include "" /*动态地址分配函数*/#define N 3 /*定义常数*/typedef struct z1 /*定义数据结构*/{ char no[11]; char name[15]; int score[N]; float sum; float average; int order; struct z1 *next;}STUDENT;/*以下是函数原型*/STUDENT *init(); /*初始化函数*/STUDENT *create(); /*创建链表*/STUDENT *delete(STUDENT *h); /*删除记录*/void print(STUDENT *h); /* 显示所有记录*/void search(STUDENT *h); /*查找*/void save(STUDENT *h); /*保存*/STUDENT *load(); /*读入记录*/void computer(STUDENT *h); /*计算总分和均分*/STUDENT *insert(STUDENT *h); /*插入记录*/void append(); /*追加记录*/void copy(); /*复制文件*/STUDENT *sort(STUDENT *h); /*排序*/STUDENT *index(STUDENT *h); /*索引*/void total(STUDENT *h); /*分类合计*/int menu_select(); /*菜单函数*//******主函数开始*******/main(){ int i; STUDENT *head; /*链表定义头指针*/ head=init(); /*初始化链表*/ clrscr(); /*清屏*/ for(;;) /*无限循环*/ { switch(menu_select()) /*调用主菜单函数,返回值整数作开关语句的条件*/ { /*值不同,执行的函数不同,break 不能省略*/ case 0:head=init();break; /*执行初始化*/ case 1:head=create();break; /*创建链表*/ case 2:head=delete(head);break; /*删除记录*/ case 3:print(head);break; /*显示全部记录*/ case 4:search(head);break; /*查找记录*/ case 5:save(head);break; /*保存文件*/ case 6:head=load(); break; /*读文件*/ case 7:computer(head);break; /*计算总分和均分*/ case 8:head=insert(head); break; /*插入记录*/ case 9:copy();break; /*复制文件*/ case 10:head=sort(head);break; /*排序*/ case 11:append();break; /*追加记录*/ case 12:head=index(head);break; /*索引*/ case 13:total(head);break; /*分类合计*/ case 14:exit(0); /*如菜单返回值为14程序结束*/ } }}/*菜单函数,返回值为整数*/menu_select(){ char *menu[]={"***************MENU***************", /*定义菜单字符串数组*/ " 0. init list", /*初始化*/ " 1. Enter list", /*输入记录*/ " 2. Delete a record from list", /*从表中删除记录*/ " 3. print list ", /*显示单链表中所有记录*/ " 4. Search record on name", /*按照姓名查找记录*/ " 5. Save the file", /*将单链表中记录保存到文件中*/ " 6. Load the file", /*从文件中读入记录*/ " 7. compute the score", /*计算所有学生的总分和均分*/ " 8. insert record to list ", /*插入记录到表中*/ " 9. copy the file to new file", /*复制文件*/ " 10. sort to make new file", /*排序*/ " 11. append record to file", /*追加记录到文件中*/ " 12. index on nomber", /*索引*/ " 13. total on nomber", /*分类合计*/ " 14. Quit"}; /*退出*/ char s[3]; /*以字符形式保存选择号*/ int c,i; /*定义整形变量*/ gotoxy(1,25); /*移动光标*/ printf("press any key enter menu......\n"); /*压任一键进入主菜单*/ getch(); /*输入任一键*/ clrscr(); /*清屏幕*/ gotoxy(1,1); /*移动光标*/ textcolor(YELLOW); /*设置文本显示颜色为黄色*/ textbackground(BLUE); /*设置背景颜色为蓝色*/ gotoxy(10,2); /*移动光标*/ putch(0xc9); /*输出左上角边框┏*/ for(i=1;i<44;i++) putch(0xcd); /*输出上边框水平线*/ putch(0xbb); /*输出右上角边框 ┓*/ for(i=3;i<20;i++) { gotoxy(10,i);putch(0xba); /*输出左垂直线*/ gotoxy(54,i);putch(0xba); } /*输出右垂直线*/ gotoxy(10,20);putch(0xc8); /*输出左上角边框┗*/ for(i=1;i<44;i++) putch(0xcd); /*输出下边框水平线*/ putch(0xbc); /*输出右下角边框┛*/ window(11,3,53,19); /* 制作显示菜单的窗口,大小根据菜单条数设计*/ clrscr(); /*清屏*/ for(i=0;i<16;i++) /*输出主菜单数组*/ { gotoxy(10,i+1); cprintf("%s",menu[i]); } textbackground(BLACK); /*设置背景颜色为黑色*/ window(1,1,80,25); /*恢复原窗口大小*/ gotoxy(10,21); /*移动光标*/ do{ printf("\n Enter you choice(0~14):"); /*在菜单窗口外显示提示信息*/ scanf("%s",s); /*输入选择项*/ c=atoi(s); /*将输入的字符串转化为整形数*/ }while(c<0||c>14); /*选择项不在0~14之间重输*/ return c; /*返回选择项,主程序根据该数调用相应的函数*/}STUDENT *init(){ return NULL;}/*创建链表*/STUDENT *create(){ int i; int s; STUDENT *h=NULL,*info; /* STUDENT指向结构体的指针*/ for(;;) { info=(STUDENT *)malloc(sizeof(STUDENT)); /*申请空间*/ if(!info) /*如果指针info为空*/ { printf("\nout of memory"); /*输出内存溢出*/ return NULL; /*返回空指针*/ } inputs("enter no:",info->no,11); /*输入学号并校验*/ if(info->no[0]=='@') break; /*如果学号首字符为@则结束输入*/ inputs("enter name:",info->name,15); /*输入姓名,并进行校验*/ printf("please input %d score \n",N); /*提示开始输入成绩*/ s=0; /*计算每个学生的总分,初值为0*/ for(i=0;i
amy20060207
本程序是用链表做的~因为是转载~不保证正确性./*头文件*/#include <>#include<>#include<> /*其它说明*/#include<> /*字符串函数*/#include<> /*内存操作函数*/#include<> /*字符操作函数*/#include<> /*动态地址分配函数*/#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",); /*显示当前系统日期*/do{ printf("\n\t\t\tEnter your choice(1~9):"); scanf("%d",&n); }while(n<1||n>9); /*如果选择项不在1~9之间则重输*/ return(n); /*返回选择项,主函数根据该数调用相应的函数*/}/*输入函数*/STUDENT *create(){int i,s;STUDENT *head=NULL,*p; /* 定义函数.此函数带回一个指向链表头的指针*/clrscr();for(;;) {p=(STUDENT *)malloc(LEN); /*开辟一个新的单元*/ if(!p) /*如果指针p为空*/ {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); }/* 显示全部记录函数*/void print(STUDENT *head){int i=0; /* 统计记录条数*/STUDENT *p; /*移动指针*/clrscr();p=head; /*初值为头指针*/printf("\n************************************STUDENT************************************\n");printf("-------------------------------------------------------------------------------\n");printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");printf("-------------------------------------------------------------------------------\n");while(p!=NULL) { i++; printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | % | %-5d|\n", i, p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order); p=p->next; }printf("-------------------------------------------------------------------------------\n");printf("**************************************END**************************************\n");}/*查找记录函数*/void search(STUDENT *head){STUDENT *p; /* 移动指针*/char s[5]; /*存放姓名用的字符数组*/clrscr();printf("Please enter name for searching.\n");scanf("%s",s);p=head; /*将头指针赋给p*/while(strcmp(p->name,s) && p != NULL) /*当记录的姓名不是要找的,或指针不为空时*/ p=p->next; /*移动指针,指向下一结点*/ if(p!=NULL) /*如果指针不为空*/ {printf("\n*************************************FOUND************************************\n"); printf("-------------------------------------------------------------------------------\n"); printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n"); printf("-------------------------------------------------------------------------------\n"); printf("| %4s | %4s | %3d | %3d | %3d | %3d | % | %-5d|\n", p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order); printf("-------------------------------------------------------------------------------\n"); printf("***************************************END**************************************\n"); } else printf("\nThere is no num %s student on the list.\n",s); /*显示没有该学生*/}/*删除记录函数*/STUDENT *delete(STUDENT *head){int n;STUDENT *p1,*p2; /*p1为查找到要删除的结点指针,p2为其前驱指针*/char c,s[6]; /*s[6]用来存放学号,c用来输入字母*/clrscr();printf("Please enter the deleted num: ");scanf("%s",s);p1=p2=head; /*给p1和p2赋初值头指针*/while(strcmp(p1->num,s) && p1 != NULL) /*当记录的学号不是要找的,或指针不为空时*/ {p2=p1; /*将p1指针值赋给p2作为p1的前驱指针*/ p1=p1->next; /*将p1指针指向下一条记录*/ }if(strcmp(p1->num,s)==0) /*学号找到了*/ {printf("**************************************FOUND************************************\n"); printf("-------------------------------------------------------------------------------\n"); printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n"); printf("-------------------------------------------------------------------------------\n"); printf("| %4s | %4s | %3d | %3d | %3d | %3d | % | %-5d|\n", p1->num,p1->name,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order); printf("-------------------------------------------------------------------------------\n"); printf("***************************************END**************************************\n"); printf("Are you sure to delete the student Y/N ?"); /*提示是否要删除,输入Y删除,N则退出*/ for(;;) {scanf("%c",&c); if(c=='n'||c=='N') break; /*如果不删除,则跳出本循环*/ if(c=='y'||c=='Y') { if(p1==head) /*若p1==head,说明被删结点是首结点*/ head=p1->next; /*把第二个结点地址赋予head*/ else p2->next=p1->next; /*否则将一下结点地址赋给前一结点地址*/ n=n-1; printf("\nNum %s student have been deleted.\n",s); printf("Don't forget to save.\n");break; /*删除后就跳出循环*/ } } } else printf("\nThere is no num %s student on the list.\n",s); /*找不到该结点*/return(head);}/*排序函数*/STUDENT *sort(STUDENT *head){int i=0; /*保存名次*/STUDENT *p1,*p2,*t,*temp; /*定义临时指针*/temp=head->next; /*将原表的头指针所指的下一个结点作头指针*/head->next=NULL; /*第一个结点为新表的头结点*/while(temp!=NULL) /*当原表不为空时,进行排序*/ { t=temp; /*取原表的头结点*/ temp=temp->next; /*原表头结点指针后移*/ p1=head; /*设定移动指针p1,从头指针开始*/ p2=head; /*设定移动指针p2做为p1的前驱,初值为头指针*/ while(t->average
优质考试培训问答知识库