
#include"stdio.h"#include"string.h"#include"malloc.h"#include"conio.h"#include"stdlib.h"#define N 3typedef struct student{long num;char name[20];int score[4];struct student* next;}Student;char menu();void input(Student*);void delete(Student*);Student* search(Student*,long);void reexamine(Student*);void display(Student*);void dispnode(Student*);void caidan();char course[4][20]={{''},{'m','a','t','h'},{'e','n','g','l','i','s','h'},{'c','o','m','p','u','t','e','r'}};Student* head;Student* p;void main(){long num;int i;clrscr();printf("\nEnter %d course names:\n",N);fflush(stdin);p=(Student*)malloc(sizeof(Student));if (p==NULL){printf("\nMemory allocation error.");exit(1);}else{p->num=0;p->next=NULL;strcpy(p->name,"head node");for(i=0;i高和橘score[i]=0;head=p;caidan();}}char menu(){char ch;int i;clrscr();printf("\n\n\t1 --- -Input\n");printf("\n\t2 --- Display\n");printf("\n\t3 --- delete\戚团n");printf("\n\t4 --- Search\n");printf("\n\t5 --- Reexamine\n");printf("\n\t6 --- Exit\棚悉n");printf("\n\n\t\t Enter your choice:");fflush(stdin);ch=getchar() ;getchar();return ch;}void input(Student* h){ long num; Student *p,*q,*r; int i,n=0; char ch; clrscr(); printf("\nEnter data for a student:\n"); printf("\nnum:"); scanf("%ld",#); while(num<3) { p=search(h,num); if (p!=NULL) { printf("\n%ld num student has been existed.",num); printf("\nReenter num for a student,please:"); fflush(stdin); scanf("%ld",#); } else { p=(Student*)malloc(sizeof(Student)); if(p==NULL) { printf("\nMemory allocation error."); exit(0); } else { n++; p->num=num; printf("\nName:"); fflush(stdin); gets(p->name); printf("\nEnter %d examine scores:",N); for(i=1;i<=N;i++) { printf("\n%s:\t",course[i]); scanf("%d",&p->score[i]); } } r=h; q=r->next; while(q!=NULL && num>q->num) { r=q; q=q->next; } r->next=p; p->next=q; clrscr(); printf("\nEnter data for a student:\n"); printf("\nnum:"); scanf("%ld",#); } } h->num=n; printf("\n There are(is) %d student(s) were(was) inserted.",n); printf("\n There are(is) total %ld student(s).",h->num); printf("press any key back to main menu!"); getchar(); caidan(); } Student* search(Student* h,long num) { Student *p,*q; q=h; p=h->next; if (p==NULL) return NULL; else { while(p!=NULL && p->num!=num) { q=p; p=p->next; } if(p!=NULL && p->num==num) return(q); else return NULL; } } void reexamine(Student* h) { Student *p; int pass; int i=0; int nopass=0; clrscr(); if(h->num==0) printf("\nThere is no student in the list."); else { p=h->next; while(p!=NULL) { pass=1; for (i=0;iscore[i]<60) {pass=0; nopass++; break; } } if (pass==0) { dispnode(p); printf("\nEnter any key to continue,please:"); getchar(); } p=p->next; } printf("\n\nThere %s total %ld student(s)",h->num,"are:",h->num); printf("\nincluded %d student%c no-pass.",nopass); printf("\nNo-pass percentage is%.2f%%.\n",(float)(nopass)/h->num *100); } } void display(Student*h) {Student*p; int many; clrscr(); if (h->num==0) printf("\nThere is no student in the list.\n"); else {p=h->next; while(p!=NULL) { dispnode(p); printf("\nEnter any to continue,please:"); getchar(); p=p->next; }; } { many=h->num>1; printf("There%s %1dstudent()s",many?"are":"is",h->num); } } void delete(Student *h) {Student *p,*q; int num; char answer; clrscr(); printf("\nEnter num of the student being deleted:"); scanf("%ld",#); q=search(h,num); if(q!=NULL) { p=q->next; dispnode(p); printf("\nDelete the student,are you sure? (Y/N):"); fflush(stdin); answer=getchar(); answer=tolower(answer); if (answer=='y') { q->next=p->next; free(p); h->num--; } else { printf("\n You change your idea,bye_bye."); } } else { printf("\nThe student to be delete is not found."); } caidan(); }void dispnode(Student* h){printf("number name score[1] score[2] score[3]\n");printf("%ld %s %d %d %d\n",h->num,h->name,h->score[1],h->score[2],h->score[3]);}void caidan(){int num;char ch;do{ch=menu();switch(ch){case '1':input(head);break;case '2':display(head);caidan();break;case '3':delete(head);break;case '4':clrscr();printf("\nEnter the number of student:");scanf("%d",#);p=search(head,num);if (p==NULL)printf("\n%ld num student is not found.",num);elsedispnode(p->next);printf("\nEnter any key to continue,please:");getchar();getchar();caidan();break;case '5':reexamine(head);printf("\nEnter any key to continue,please:");getchar();caidan();break;case '6':printf("\nExit the program now,bye_bye!");exit(0);break;default:printf("\nYou should press <1> --<6>");if(ch=='\n' || ch=='\t' ||ch=='')printf("\nch is thite character.\n");elseprintf("\nch=%c\n",&ch);break;}}while(ch=='6');}
标签:c#,管理系统,编写
版权声明:文章由 知识百问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.zhshbaiwen.com/answer/98481.html