木有雨啊
第一頁(yè)/* 源程序*//**********************//******頭文件(.h)***********/#include "" /*I/O函數(shù)*/#include "" /*其它說明*/#include "" /*字符串函數(shù)*/#include "" /*屏幕操作函數(shù)*/#include "" /*內(nèi)存操作函數(shù)*/#include "" /*字符操作函數(shù)*/#include "" /*動(dòng)態(tài)地址分配函數(shù)*/#define N 3 /*定義常數(shù)*/typedef struct z1 /*定義數(shù)據(jù)結(jié)構(gòu)*/{ char no[11]; char name[15]; int score[N]; float sum; float average; int order; struct z1 *next;}STUDENT;/*以下是函數(shù)原型*/STUDENT *init(); /*初始化函數(shù)*/STUDENT *create(); /*創(chuàng)建鏈表*/STUDENT *delete(STUDENT *h); /*刪除記錄*/void print(STUDENT *h); /* 顯示所有記錄*/void search(STUDENT *h); /*查找*/void save(STUDENT *h); /*保存*/STUDENT *load(); /*讀入記錄*/void computer(STUDENT *h); /*計(jì)算總分和均分*/STUDENT *insert(STUDENT *h); /*插入記錄*/void append(); /*追加記錄*/void copy(); /*復(fù)制文件*/STUDENT *sort(STUDENT *h); /*排序*/STUDENT *index(STUDENT *h); /*索引*/void total(STUDENT *h); /*分類合計(jì)*/int menu_select(); /*菜單函數(shù)*//******主函數(shù)開始*******/main(){ int i; STUDENT *head; /*鏈表定義頭指針*/ head=init(); /*初始化鏈表*/ clrscr(); /*清屏*/ for(;;) /*無(wú)限循環(huán)*/ { switch(menu_select()) /*調(diào)用主菜單函數(shù),返回值整數(shù)作開關(guān)語(yǔ)句的條件*/ { /*值不同,執(zhí)行的函數(shù)不同,break 不能省略*/ case 0:head=init();break; /*執(zhí)行初始化*/ case 1:head=create();break; /*創(chuàng)建鏈表*/ 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; /*計(jì)算總分和均分*/ case 8:head=insert(head); break; /*插入記錄*/ case 9:copy();break; /*復(fù)制文件*/ case 10:head=sort(head);break; /*排序*/ case 11:append();break; /*追加記錄*/ case 12:head=index(head);break; /*索引*/ case 13:total(head);break; /*分類合計(jì)*/ case 14:exit(0); /*如菜單返回值為14程序結(jié)束*/ } }}/*菜單函數(shù),返回值為整數(shù)*/menu_select(){ char *menu[]={"***************MENU***************", /*定義菜單字符串?dāng)?shù)組*/ " 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", /*計(jì)算所有學(xué)生的總分和均分*/ " 8. insert record to list ", /*插入記錄到表中*/ " 9. copy the file to new file", /*復(fù)制文件*/ " 10. sort to make new file", /*排序*/ " 11. append record to file", /*追加記錄到文件中*/ " 12. index on nomber", /*索引*/ " 13. total on nomber", /*分類合計(jì)*/ " 14. Quit"}; /*退出*/ char s[3]; /*以字符形式保存選擇號(hào)*/ int c,i; /*定義整形變量*/ gotoxy(1,25); /*移動(dòng)光標(biāo)*/ printf("press any key enter menu......\n"); /*壓任一鍵進(jìn)入主菜單*/ getch(); /*輸入任一鍵*/ clrscr(); /*清屏幕*/ gotoxy(1,1); /*移動(dòng)光標(biāo)*/ textcolor(YELLOW); /*設(shè)置文本顯示顏色為黃色*/ textbackground(BLUE); /*設(shè)置背景顏色為藍(lán)色*/ gotoxy(10,2); /*移動(dòng)光標(biāo)*/ 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); /* 制作顯示菜單的窗口,大小根據(jù)菜單條數(shù)設(shè)計(jì)*/ clrscr(); /*清屏*/ for(i=0;i<16;i++) /*輸出主菜單數(shù)組*/ { gotoxy(10,i+1); cprintf("%s",menu[i]); } textbackground(BLACK); /*設(shè)置背景顏色為黑色*/ window(1,1,80,25); /*恢復(fù)原窗口大小*/ gotoxy(10,21); /*移動(dòng)光標(biāo)*/ do{ printf("\n Enter you choice(0~14):"); /*在菜單窗口外顯示提示信息*/ scanf("%s",s); /*輸入選擇項(xiàng)*/ c=atoi(s); /*將輸入的字符串轉(zhuǎn)化為整形數(shù)*/ }while(c<0||c>14); /*選擇項(xiàng)不在0~14之間重輸*/ return c; /*返回選擇項(xiàng),主程序根據(jù)該數(shù)調(diào)用相應(yīng)的函數(shù)*/}STUDENT *init(){ return NULL;}/*創(chuàng)建鏈表*/STUDENT *create(){ int i; int s; STUDENT *h=NULL,*info; /* STUDENT指向結(jié)構(gòu)體的指針*/ for(;;) { info=(STUDENT *)malloc(sizeof(STUDENT)); /*申請(qǐng)空間*/ if(!info) /*如果指針info為空*/ { printf("\nout of memory"); /*輸出內(nèi)存溢出*/ return NULL; /*返回空指針*/ } inputs("enter no:",info->no,11); /*輸入學(xué)號(hào)并校驗(yàn)*/ if(info->no[0]=='@') break; /*如果學(xué)號(hào)首字符為@則結(jié)束輸入*/ inputs("enter name:",info->name,15); /*輸入姓名,并進(jìn)行校驗(yàn)*/ printf("please input %d score \n",N); /*提示開始輸入成績(jī)*/ s=0; /*計(jì)算每個(gè)學(xué)生的總分,初值為0*/ for(i=0;i
amy20060207
本程序是用鏈表做的~因?yàn)槭寝D(zhuǎn)載~不保證正確性./*頭文件*/#include <>#include<>#include<> /*其它說明*/#include<> /*字符串函數(shù)*/#include<> /*內(nèi)存操作函數(shù)*/#include<> /*字符操作函數(shù)*/#include<> /*動(dòng)態(tài)地址分配函數(shù)*/#define LEN sizeof(STUDENT)typedef struct stu /*定義結(jié)構(gòu)體數(shù)組用于緩存數(shù)據(jù)*/{char num[6];char name[5];int score[3];int sum;float average;int order;struct stu *next;}STUDENT;/*函數(shù)原型*/STUDENT *init(); /*初始化函數(shù)*/int menu_select(); /*菜單函數(shù)*/STUDENT *create(); /*創(chuàng)建鏈表*/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(); /*讀文件*//*主函數(shù)界面*/main(){STUDENT *head,new;head=init(); /*鏈表初始化,使head的值為NULL*/for(;;) /*循環(huán)無(wú)限次*/ {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則程序結(jié)束*/ } }}/*初始化函數(shù)*/STUDENT *init(){return NULL; /*返回空指針*/}/*菜單選擇函數(shù)*/menu_select(){int n;struct date d; /*定義時(shí)間結(jié)構(gòu)體*/getdate(&d); /*讀取系統(tǒng)日期并把它放到結(jié)構(gòu)體d中*/printf("press any key to enter the menu......"); /*按任一鍵進(jìn)入主菜單*/getch(); /*從鍵盤讀取一個(gè)字符,但不顯示于屏幕*/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"); /*輸入學(xué)生成績(jī)記錄*/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āng)前系統(tǒng)日期*/do{ printf("\n\t\t\tEnter your choice(1~9):"); scanf("%d",&n); }while(n<1||n>9); /*如果選擇項(xiàng)不在1~9之間則重輸*/ return(n); /*返回選擇項(xiàng),主函數(shù)根據(jù)該數(shù)調(diào)用相應(yīng)的函數(shù)*/}/*輸入函數(shù)*/STUDENT *create(){int i,s;STUDENT *head=NULL,*p; /* 定義函數(shù).此函數(shù)帶回一個(gè)指向鏈表頭的指針*/clrscr();for(;;) {p=(STUDENT *)malloc(LEN); /*開辟一個(gè)新的單元*/ if(!p) /*如果指針p為空*/ {printf("\nOut of memory."); /*輸出內(nèi)存溢出*/ return (head); /*返回頭指針,下同*/ } printf("Enter the num(0:list end):"); scanf("%s",p->num); if(p->num[0]=='0') break; /*如果學(xué)號(hào)首字符為0則結(jié)束輸入*/ printf("Enter the name:"); scanf("%s",p->name); printf("Please enter the %d scores\n",3); /*提示開始輸入成績(jī)*/ s=0; /*計(jì)算每個(gè)學(xué)生的總分,初值為0*/ for(i=0;i<3;i++) /*3門課程循環(huán)3次*/ { do{ printf("score%d:",i+1); scanf("%d",&p->score[i]); if(p->score[i]<0 || p->score[i]>100) /*確保成績(jī)?cè)?~100之間*/ printf("Data error,please enter again.\n"); }while(p->score[i]<0 || p->score[i]>100); s=s+p->score[i]; /*累加各門成績(jī)*/ } p->sum=s; /*將總分保存*/ p->average=(float)s/3; /*先用強(qiáng)制類型轉(zhuǎn)換將s轉(zhuǎn)換成float型,再求平均值*/ p->order=0; /*未排序前此值為0*/ p->next=head; /*將頭結(jié)點(diǎn)做為新輸入結(jié)點(diǎn)的后繼結(jié)點(diǎn)*/ head=p; /*新輸入結(jié)點(diǎn)為新的頭結(jié)點(diǎn)*/ } return(head); }/* 顯示全部記錄函數(shù)*/void print(STUDENT *head){int i=0; /* 統(tǒng)計(jì)記錄條數(shù)*/STUDENT *p; /*移動(dòng)指針*/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");}/*查找記錄函數(shù)*/void search(STUDENT *head){STUDENT *p; /* 移動(dòng)指針*/char s[5]; /*存放姓名用的字符數(shù)組*/clrscr();printf("Please enter name for searching.\n");scanf("%s",s);p=head; /*將頭指針賦給p*/while(strcmp(p->name,s) && p != NULL) /*當(dāng)記錄的姓名不是要找的,或指針不為空時(shí)*/ p=p->next; /*移動(dòng)指針,指向下一結(jié)點(diǎn)*/ 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); /*顯示沒有該學(xué)生*/}/*刪除記錄函數(shù)*/STUDENT *delete(STUDENT *head){int n;STUDENT *p1,*p2; /*p1為查找到要?jiǎng)h除的結(jié)點(diǎn)指針,p2為其前驅(qū)指針*/char c,s[6]; /*s[6]用來存放學(xué)號(hào),c用來輸入字母*/clrscr();printf("Please enter the deleted num: ");scanf("%s",s);p1=p2=head; /*給p1和p2賦初值頭指針*/while(strcmp(p1->num,s) && p1 != NULL) /*當(dāng)記錄的學(xué)號(hào)不是要找的,或指針不為空時(shí)*/ {p2=p1; /*將p1指針值賦給p2作為p1的前驅(qū)指針*/ p1=p1->next; /*將p1指針指向下一條記錄*/ }if(strcmp(p1->num,s)==0) /*學(xué)號(hào)找到了*/ {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 ?"); /*提示是否要?jiǎng)h除,輸入Y刪除,N則退出*/ for(;;) {scanf("%c",&c); if(c=='n'||c=='N') break; /*如果不刪除,則跳出本循環(huán)*/ if(c=='y'||c=='Y') { if(p1==head) /*若p1==head,說明被刪結(jié)點(diǎn)是首結(jié)點(diǎn)*/ head=p1->next; /*把第二個(gè)結(jié)點(diǎn)地址賦予head*/ else p2->next=p1->next; /*否則將一下結(jié)點(diǎn)地址賦給前一結(jié)點(diǎn)地址*/ n=n-1; printf("\nNum %s student have been deleted.\n",s); printf("Don't forget to save.\n");break; /*刪除后就跳出循環(huán)*/ } } } else printf("\nThere is no num %s student on the list.\n",s); /*找不到該結(jié)點(diǎn)*/return(head);}/*排序函數(shù)*/STUDENT *sort(STUDENT *head){int i=0; /*保存名次*/STUDENT *p1,*p2,*t,*temp; /*定義臨時(shí)指針*/temp=head->next; /*將原表的頭指針?biāo)傅南乱粋€(gè)結(jié)點(diǎn)作頭指針*/head->next=NULL; /*第一個(gè)結(jié)點(diǎn)為新表的頭結(jié)點(diǎn)*/while(temp!=NULL) /*當(dāng)原表不為空時(shí),進(jìn)行排序*/ { t=temp; /*取原表的頭結(jié)點(diǎn)*/ temp=temp->next; /*原表頭結(jié)點(diǎn)指針后移*/ p1=head; /*設(shè)定移動(dòng)指針p1,從頭指針開始*/ p2=head; /*設(shè)定移動(dòng)指針p2做為p1的前驅(qū),初值為頭指針*/ while(t->average
優(yōu)質(zhì)考試培訓(xùn)問答知識(shí)庫(kù)