C语言 学生成绩管理系统 c语言学生信息管理系统代码
\u7528C\u8bed\u8a00\u8bbe\u8ba1\u4e00\u4e2a\u5b66\u751f\u6210\u7ee9\u7ba1\u7406\u7cfb\u7edf#include #include
#include #define MAX 1000/*\u5b9a\u4e49\u5b66\u751f\u6210\u7ee9\u4fe1\u606f\u7ed3\u6784*/struct stu{
char id[8];char name[8];
\u6269\u5c55\u8d44\u6599\uff1a
short\uff1a\u4fee\u9970int\uff0c\u77ed\u6574\u578b\u6570\u636e\uff0c\u53ef\u7701\u7565\u88ab\u4fee\u9970\u7684int\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
long\uff1a\u4fee\u9970int\uff0c\u957f\u6574\u578b\u6570\u636e\uff0c\u53ef\u7701\u7565\u88ab\u4fee\u9970\u7684int\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
long long\uff1a\u4fee\u9970int\uff0c\u8d85\u957f\u6574\u578b\u6570\u636e\uff0c\u53ef\u7701\u7565\u88ab\u4fee\u9970\u7684int\u3002\uff08C99\u6807\u51c6\u65b0\u589e\uff09
signed\uff1a\u4fee\u9970\u6574\u578b\u6570\u636e\uff0c\u6709\u7b26\u53f7\u6570\u636e\u7c7b\u578b\u3002\uff08C89\u6807\u51c6\u65b0\u589e\uff09
unsigned\uff1a\u4fee\u9970\u6574\u578b\u6570\u636e\uff0c\u65e0\u7b26\u53f7\u6570\u636e\u7c7b\u578b\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
restrict:\u7528\u4e8e\u9650\u5b9a\u548c\u7ea6\u675f\u6307\u9488\uff0c\u5e76\u8868\u660e\u6307\u9488\u662f\u8bbf\u95ee\u4e00\u4e2a\u6570\u636e\u5bf9\u8c61\u7684\u552f\u4e00\u4e14\u521d\u59cb\u7684\u65b9\u5f0f\u3002\uff08C99\u6807\u51c6\u65b0\u589e\uff09
\u590d\u6742\u7c7b\u578b\u5173\u952e\u5b57
struct\uff1a\u7ed3\u6784\u4f53\u58f0\u660e\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
union\uff1a\u8054\u5408\u4f53\u58f0\u660e\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
enum\uff1a\u679a\u4e3e\u58f0\u660e\u3002\uff08C89\u6807\u51c6\u65b0\u589e\uff09
typedef\uff1a\u58f0\u660e\u7c7b\u578b\u522b\u540d\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
sizeof\uff1a\u5f97\u5230\u7279\u5b9a\u7c7b\u578b\u6216\u7279\u5b9a\u7c7b\u578b\u53d8\u91cf\u7684\u5927\u5c0f\u3002\uff08K&R\u65f6\u671f\u5f15\u5165\uff09
inline:\u5185\u8054\u51fd\u6570\u7528\u4e8e\u53d6\u4ee3\u5b8f\u5b9a\u4e49\uff0c\u4f1a\u5728\u4efb\u4f55\u8c03\u7528\u5b83\u7684\u5730\u65b9\u5c55\u5f00\u3002\uff08C99\u6807\u51c6\u65b0\u589e\uff09
\u53c2\u8003\u8d44\u6599\u6765\u6e90\uff1a\u767e\u5ea6\u767e\u79d1-c\u8bed\u8a00
\u4ee3\u7801\u5982\u4e0b\uff1a
#include#include#include#include#includetypedef struct examinee //\u8003\u751f\u4fe1\u606f\u7ed3\u6784{ char examno[20]; //\u51c6\u8003\u8bc1\u53f7char name[10]; //\u59d3\u540dchar sex[4]; //\u6027\u522bshort age; //\u5e74\u9f84char examtype[10]; //\u62a5\u8003\u79d1\u76ee}ElemType;
typedef struct Node //\u5b9a\u4e49\u94fe\u8868\u7ed3\u70b9{ElemType data; //\u6570\u636e\u57dfstruct Node *next; //\u6307\u9488\u57df }Node,*List,*position;
List make_empty( List L ); //\u521b\u5efa\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u7a7a\u8868int is_empty( List L ); //\u6d4b\u8bd5\u94fe\u8868\u662f\u5426\u662f\u7a7a\u8868int is_last( position p, List L ); //\u6d4b\u8bd5\u5f53\u524d\u4f4d\u7f6e\u662f\u5426\u662f\u8868\u5c3eposition make_node( position p,int n ); //\u521b\u5efa\u7ed3\u70b9\u5e76\u8f93\u5165\u8003\u751f\u4fe1\u606fvoid put_information( position p ); //\u662f\u5426\u8f93\u51fa\u8be5\u8003\u751f\u4fe1\u606f void put_name_information( List L ); //\u8f93\u51fa\u59d3\u540d\u4e3axx\u7684\u8003\u751f\u4fe1\u606fint put_pos_information( position p ); //\u8f93\u51fa\u8be5\u5730\u5740\u8003\u751f\u4fe1\u606f void link_to_tail( List L, position p ); //\u5c06\u7ed3\u70b9\u8fde\u63a5\u5230\u8868\u5c3e int ciculation_make(); //\u5faa\u73af\u521b\u5efa\u8003\u751f\u4fe1\u606f int judge_put_all(); //\u662f\u5426\u8f93\u51fa\u6240\u6709\u8003\u751f\u4fe1\u606fvoid put_all(List L); //\u8f93\u51fa\u6240\u6709\u8003\u751f\u4fe1\u606f\u3002position find( List L ); //\u67e5\u627e\u7b2c\u4e00\u4e2a\u59d3\u540d\u4e3axx\u7684\u5143\u7d20\u5e76\u8fd4\u56de\u4f4d\u7f6eposition find_previous( List L ); //\u67e5\u627e\u7b2c\u4e00\u4e2a\u59d3\u540d\u4e3axx\u7684\u5143\u7d20\u5e76\u8fd4\u56de\u8be5\u5143\u7d20\u76f4\u63a5\u524d\u9a71\u7684\u4f4d\u7f6e//int judge_delete_val(); //\u8be2\u95ee\u662f\u5426\u5220\u9664\u8003\u751f\u6570\u636eint delete_val( List L ); //\u5220\u9664\u6307\u5b9a\u8003\u751f\u4fe1\u606f\u5e76\u8f93\u51fa\u5176\u4fe1\u606fvoid menu(List L); //\u83dc\u5355\u51fd\u6570 List L;//position p;
intmain( void ) {List L = NULL; //\u5b9a\u4e49\u5934\u7ed3\u70b9\u6307\u9488position p = NULL; //\u5b9a\u4e49\u8868\u5de5\u4f5c\u6307\u9488L = make_empty( L ); //\u521b\u5efa\u7a7a\u8868printf("\t\t\t\u2605\u2605\u8003\u751f\u62a5\u540d\u7ba1\u7406\u7a0b\u5e8f\u2605\u2605\n\t\t----------------------------------------\n");menu(L);return 0;}
//\u521b\u5efa\u4e00\u4e2a\u5e26\u5934\u7ed3\u70b9\u7684\u7a7a\u8868Listmake_empty( List L){L = ( List ) malloc (sizeof( Node ));if(NULL == L){printf("\u5185\u5b58\u5206\u914d\u5931\u8d25");exit( 1 );}L->next = NULL;//printf("\u7a7a\u8868\u521b\u5efa\u6210\u529f\u3002\n");return L;}
//\u521b\u5efa\u7ed3\u70b9\u5e76\u8f93\u5165\u8003\u751f\u4fe1\u606fpositionmake_node( position p ,int n){if(n) //n\u4e3a1\u662f\u521b\u5efa\u7ed3\u70b9\u5e76\u8f93\u5165\uff0cn\u4e3a0\u662f\u4fee\u6539{p = ( position ) malloc ( sizeof ( Node ));p->next = NULL ;}printf("\u8bf7\u8f93\u5165\u8003\u751f\u51c6\u8003\u8bc1\u53f7\uff1a");gets(p->data.examno);printf("\u8bf7\u8f93\u5165\u8003\u751f\u59d3\u540d\uff1a");gets(p->data.name);do{printf("\u8bf7\u8f93\u5165\u8003\u751f\u6027\u522b,\u53ea\u80fd\u8f93\u5165\u201c\u7537\u201d\u6216\u8005\u201c\u5973\u201d\uff1a");gets(p->data.sex);}while( 0 != strcmp( p->data.sex, "\u7537" ) && 0 != strcmp( p->data.sex, "\u5973" )); //\u5224\u65ad\u6027\u522b\u662f\u5426\u6709\u8befprintf("\u8bf7\u8f93\u5165\u8003\u751f\u5e74\u9f84\uff1a");scanf("%hd",&p->data.age);getchar(); //\u5982\u679c\u628a\u8fd9\u53e5\u5220\u6389\uff0c\u5c31\u201c\u65e0\u6cd5\u6267\u884c\u201d\u4e0b\u9762\u7684\u62a5\u8003\u7c7b\u522b/*\u4e0b\u9762\u7684do while\u7528\u6765\u5224\u65ad\u62a5\u8003\u7c7b\u522b\u662f\u5426\u8f93\u5165\u6709\u8bef*/do{printf("\u8bf7\u8f93\u5165\u62a5\u8003\u7c7b\u522b,\u53ea\u80fd\u8f93\u5165\u201c\u6570\u5b66\u201d\u6216\u201c\u82f1\u8bed\u201d\u6216\u8005\u201c\u6570\u636e\u7ed3\u6784\u201d\uff1a");gets(p->data.examtype);}while( 0 != strcmp( "\u82f1\u8bed", p->data.examtype ) && 0 != strcmp( "\u6570\u5b66", p->data.examtype ) && 0 != strcmp( "\u6570\u636e\u7ed3\u6784", p->data.examtype ));if(n){printf("\u62a5\u540d\u6210\u529f\n");}else{printf("\u4fee\u6539\u6210\u529f\n");}return p;}
//\u524d\u63d2\u6cd5\uff1b voidlink_to_tail( List L, position p){p->next = L->next;L->next = p;}
//\u67e5\u627e\u7b2c\u4e00\u4e2a\u59d3\u540d\u4e3axx\u7684\u5143\u7d20\u5e76\u8fd4\u56de\u4f4d\u7f6epositionfind( List L ){position p = L->next;char name[10];printf("\u8bf7\u8f93\u5165\u4f60\u8981\u67e5\u627e\u7684\u8003\u751f\u59d3\u540d\uff1a");gets(name);while( p != NULL && 0 != strcmp( p->data.name , name)){p=p->next;}return p;}//\u6d4b\u8bd5\u94fe\u8868\u662f\u5426\u662f\u7a7a\u8868intis_empty( List L ){return L->next == NULL;}//\u6d4b\u8bd5\u5f53\u524d\u4f4d\u7f6e\u662f\u5426\u662f\u8868\u5c3eintis_last( position p, List L ){return p->next == NULL;}//\u8f93\u51fa\u59d3\u540d\u4e3axx\u7684\u8003\u751f\u4fe1\u606fvoidput_name_information( List L ){position p = find(L);if(p!=NULL){printf("\u60a8\u8981\u67e5\u627e\u7684\u8003\u751f\u4fe1\u606f\uff1a\n");printf("\u51c6\u8003\u8bc1\u53f7\uff1a%s\t\u59d3\u540d\uff1a%s\t\u6027\u522b\uff1a%s\t\u5e74\u9f84\uff1a%hd\t\u62a5\u8003\u79d1\u76ee\uff1a%s\n\n",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);}else{printf("\u6ca1\u6709\u60a8\u8981\u627e\u7684\u5b66\u751f\u3002\n");}}//\u5faa\u73af\u521b\u5efa\u8003\u751f\u4fe1\u606f intciculation_make(){int n = 2;do{printf("\u662f\u5426\u7ee7\u7eed\u521b\u5efa\u8003\u751f\u4fe1\u606f\uff1f\u662f\u8bf7\u8f93\u5165\u201c1\u201d\uff0c\u4e0d\u662f\u8bf7\u8f93\u5165\u201c0\u201d\uff1a");scanf("%d",&n);getchar();}while( n != 0 && n != 1);return n;}
//\u662f\u5426\u8f93\u51fa\u8003\u751f\u4fe1\u606f voidput_information( position p ){int n=2;do{printf("\u662f\u5426\u8f93\u51fa\u8be5\u8003\u751f\u4fe1\u606f\uff1f\u662f\u8bf7\u8f93\u5165\u201c1\u201d\uff0c\u4e0d\u662f\u8bf7\u8f93\u5165\u201c0\u201d\uff1a");scanf("%d",&n);getchar();}while( n != 0 && n != 1);if(n){printf("\u51c6\u8003\u8bc1\u53f7\uff1a%s\t\u59d3\u540d\uff1a%s\t\u6027\u522b\uff1a%s\t\u5e74\u9f84\uff1a%hd\t\u62a5\u8003\u79d1\u76ee\uff1a%s\n",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);}}
//\u662f\u5426\u8f93\u51fa\u6240\u6709\u8003\u751f\u4fe1\u606f int judge_put_all(){int n = 2;do{printf("\u662f\u5426\u8f93\u51fa\u6240\u6709\u8003\u751f\u4fe1\u606f\uff1f\u662f\u8bf7\u8f93\u5165\u201c1\u201d\uff0c\u4e0d\u662f\u8bf7\u8f93\u5165\u201c0\u201d\uff1a");scanf("%d",&n);getchar();}while( n != 0 && n != 1);return n;}
//\u8f93\u51fa\u6240\u6709\u8003\u751f\u4fe1\u606fvoidput_all(List L){if(L->next == NULL){printf("\u73b0\u65e0\u8003\u751f\u62a5\u540d\uff01\n");}else{position p=L->next;while( p != NULL ){printf("\u51c6\u8003\u8bc1\u53f7\uff1a%s\t\u59d3\u540d\uff1a%s\t\u6027\u522b\uff1a%s\t\u5e74\u9f84\uff1a%hd\t\u62a5\u8003\u79d1\u76ee\uff1a%s\n",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);p=p->next;}}//getchar();}
//\u8be2\u95ee\u662f\u5426\u5220\u9664\u8003\u751f\u6570\u636eintjudge_delete_val(){int n = 2;
do{printf("\u662f\u5426\u8981\u5220\u9664\u67d0\u4e2a\u8003\u751f\u6570\u636e\uff1f\u662f\u8bf7\u8f93\u5165\u201c1\u201d\uff0c\u4e0d\u662f\u8f93\u5165\u201c0\u201d\uff1a");scanf("%d",&n);getchar();}while( n != 0 && n != 1);return n;}
//\u67e5\u627e\u7b2c\u4e00\u4e2a\u59d3\u540d\u4e3axx\u7684\u5143\u7d20\u5e76\u8fd4\u56de\u5176\u76f4\u63a5\u524d\u9a71\u7684\u4f4d\u7f6epositionfind_previous( List L ){position q = L;position p = L->next;char name[10];printf("\u8bf7\u8f93\u5165\u4f60\u8981\u67e5\u627e\u7684\u8003\u751f\u59d3\u540d\uff1a");gets(name);while( p != NULL && 0 != strcmp( p->data.name , name)){q=p;p=p->next;}if( p != NULL ){return q;}elsereturn p;}
//\u5220\u9664\u6307\u5b9a\u8003\u751f\u4fe1\u606f\u5e76\u8f93\u51fa\u5176\u4fe1\u606fintdelete_val(List L){int n=2;position q=NULL;position p=find_previous( L ); //\u8fd4\u56de\u8003\u751f\u4fe1\u606f\u5730\u5740if( NULL == p ){printf("\u4f60\u8981\u5220\u9664\u7684\u8003\u751f\u4e0d\u5b58\u5728\n");return 0;}else{q = p->next;p->next = q->next;printf("\u5220\u9664\u6210\u529f\u3002\n\u5220\u9664\u7684\u8003\u751f\u4fe1\u606f\u4e3a\uff1a\n");printf("\u51c6\u8003\u8bc1\u53f7\uff1a%s\t\u59d3\u540d\uff1a%s\t\u6027\u522b\uff1a%s\t\u5e74\u9f84\uff1a%hd\t\u62a5\u8003\u79d1\u76ee\uff1a%s\n",q->data.examno,q->data.name,q->data.sex,q->data.age,q->data.examtype);free(q);return 1;}
}
//\u8f93\u51fa\u8be5\u5730\u5740\u8003\u8bd5\u4fe1\u606f intput_pos_information( position p ){if(p != NULL ){printf("\u51c6\u8003\u8bc1\u53f7\uff1a%s\t\u59d3\u540d\uff1a%s\t\u6027\u522b\uff1a%s\t\u5e74\u9f84\uff1a%hd\t\u62a5\u8003\u79d1\u76ee\uff1a%s\n\n",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);return 1;}else{printf("\u6ca1\u6709\u60a8\u8981\u67e5\u627e\u7684\u5b66\u751f\u3002");return 0;}} //\u83dc\u5355\u51fd\u6570voidmenu(List L){printf("\t\t\t a. \u8003\u751f\u62a5\u540d\u5165\u53e3\n");printf("\t\t\t b. \u67e5\u8be2\u8003\u751f\u4fe1\u606f\n");printf("\t\t\t c. \u4fee\u6539\u8003\u751f\u4fe1\u606f\n");printf("\t\t\t d. \u5220\u9664\u8003\u751f\u4fe1\u606f\n");printf("\t\t\t e. \u5168\u90e8\u8003\u751f\u4fe1\u606f\n");printf("\t\t\t f. \u7a0b\u5e8f\u4f5c\u8005\u4fe1\u606f\n");printf("\t\t\t g. \u9000\u51fa\u7a0b\u5e8f\n");char n='h';while(n != 'g'){do //\u786e\u5b9a\u6b63\u786e\u8f93\u5165{printf("\u8bf7\u901a\u8fc7\u5b57\u6bcd\u5e8f\u53f7\u9009\u62e9\u529f\u80fd\uff1a");n = getchar();getchar();putchar('\n');if( n 'g'){printf("\u9519\u8bef\u7684\u5b57\u6bcd\u5e8f\u53f7\u3002\n");}}while( n 'g' );switch (n){case 'a':{printf("\u8bf7\u8f93\u5165\u62a5\u540d\u8003\u751f\u4fe1\u606f\uff1a\n");position p = make_node( p, 1 ); //\u521b\u5efa\u65b0\u7ed3\u70b9link_to_tail( L, p ); //\u5c06\u65b0\u7ed3\u70b9\u8fde\u63a5\u5230\u8868\u4e0aput_information( p ); //\u662f\u5426\u8f93\u51fa\u8be5\u8003\u751f\u4fe1\u606fputchar('\n');}break;
case 'b':{put_name_information( L );putchar('\n');}break;
case 'c':{int n=0;position p = NULL;printf("\u60a8\u6b63\u5728\u8fdb\u884c\u4fee\u6539\u64cd\u4f5c\u3002\n");p = find(L);n = put_pos_information( p );if(n){make_node( p , 0 );put_information( p ); //\u662f\u5426\u8f93\u51fa\u8be5\u8003\u751f\u4fe1\u606f}putchar('\n');}break;
case 'd':{printf("\u60a8\u6b63\u5728\u8fdb\u884c\u5220\u9664\u64cd\u4f5c\u3002\n");delete_val( L );putchar('\n');}break;
case 'e':{put_all( L );putchar('\n');}break;
case 'f':{printf(" \u4fee\u6539\u65e5\u671f \u7248\u672c\u53f7 \u4fee\u6539\u4eba \u4fee\u6539\u5185\u5bb9 \n");printf(" --------------------------------------------------------\n");printf(" 2018.6.19 v2.0 \u9648\u767e\u5ddd \u589e\u52a0\u4e3b\u83dc\u5355\n");printf(" 2018.6.23 v3.0 \u9648\u767e\u5ddd \u589e\u52a0\u751f\u6210\u6587\u4ef6\u529f\u80fd\n\n");printf(" \u8be5\u7248\u672c\u53f7\u4e3av2.0\n");putchar('\n');}break;
default:break;}}printf(" \u611f\u8c22\u672c\u6b21\u4f7f\u7528\uff0c\u795d\u60a8\u751f\u6d3b\u6109\u5feb\u3002");getch(); }
\u6269\u5c55\u8d44\u6599\uff1aC\u8bed\u8a00\u662f\u4e00\u95e8\u901a\u7528\u8ba1\u7b97\u673a\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5e95\u5c42\u5f00\u53d1\u3002C\u8bed\u8a00\u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u63d0\u4f9b\u4e00\u79cd\u80fd\u4ee5\u7b80\u6613\u7684\u65b9\u5f0f\u7f16\u8bd1\u3001\u5904\u7406\u4f4e\u7ea7\u5b58\u50a8\u5668\u3001\u4ea7\u751f\u5c11\u91cf\u7684\u673a\u5668\u7801\u4ee5\u53ca\u4e0d\u9700\u8981\u4efb\u4f55\u8fd0\u884c\u73af\u5883\u652f\u6301\u4fbf\u80fd\u8fd0\u884c\u7684\u7f16\u7a0b\u8bed\u8a00\u3002
\u5c3d\u7ba1C\u8bed\u8a00\u63d0\u4f9b\u4e86\u8bb8\u591a\u4f4e\u7ea7\u5904\u7406\u7684\u529f\u80fd\uff0c\u4f46\u4ecd\u7136\u4fdd\u6301\u7740\u826f\u597d\u8de8\u5e73\u53f0\u7684\u7279\u6027\uff0c\u4ee5\u4e00\u4e2a\u6807\u51c6\u89c4\u683c\u5199\u51fa\u7684C\u8bed\u8a00\u7a0b\u5e8f\u53ef\u5728\u8bb8\u591a\u7535\u8111\u5e73\u53f0\u4e0a\u8fdb\u884c\u7f16\u8bd1\uff0c\u751a\u81f3\u5305\u542b\u4e00\u4e9b\u5d4c\u5165\u5f0f\u5904\u7406\u5668\uff08\u5355\u7247\u673a\u6216\u79f0MCU\uff09\u4ee5\u53ca\u8d85\u7ea7\u7535\u8111\u7b49\u4f5c\u4e1a\u5e73\u53f0\u3002
\u4e8c\u5341\u4e16\u7eaa\u516b\u5341\u5e74\u4ee3\uff0c\u4e3a\u4e86\u907f\u514d\u5404\u5f00\u53d1\u5382\u5546\u7528\u7684C\u8bed\u8a00\u8bed\u6cd5\u4ea7\u751f\u5dee\u5f02\uff0c\u7531\u7f8e\u56fd\u56fd\u5bb6\u6807\u51c6\u5c40\u4e3aC\u8bed\u8a00\u5236\u5b9a\u4e86\u4e00\u5957\u5b8c\u6574\u7684\u7f8e\u56fd\u56fd\u5bb6\u6807\u51c6\u8bed\u6cd5\uff0c\u79f0\u4e3aANSI C\uff0c\u4f5c\u4e3aC\u8bed\u8a00\u6700\u521d\u7684\u6807\u51c6\u3002[1] \u76ee\u524d2011\u5e7412\u67088\u65e5\uff0c\u56fd\u9645\u6807\u51c6\u5316\u7ec4\u7ec7\uff08ISO\uff09\u548c\u56fd\u9645\u7535\u5de5\u59d4\u5458\u4f1a\uff08IEC\uff09\u53d1\u5e03\u7684C11\u6807\u51c6\u662fC\u8bed\u8a00\u7684\u7b2c\u4e09\u4e2a\u5b98\u65b9\u6807\u51c6\uff0c\u4e5f\u662fC\u8bed\u8a00\u7684\u6700\u65b0\u6807\u51c6\uff0c\u8be5\u6807\u51c6\u66f4\u597d\u7684\u652f\u6301\u4e86\u6c49\u5b57\u51fd\u6570\u540d\u548c\u6c49\u5b57\u6807\u8bc6\u7b26\uff0c\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u5b9e\u73b0\u4e86\u6c49\u5b57\u7f16\u7a0b\u3002
C\u8bed\u8a00\u662f\u4e00\u95e8\u9762\u5411\u8fc7\u7a0b\u7684\u8ba1\u7b97\u673a\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e0eC++\uff0cJava\u7b49\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u6709\u6240\u4e0d\u540c\u3002
\u5176\u7f16\u8bd1\u5668\u4e3b\u8981\u6709Clang\u3001GCC\u3001WIN-TC\u3001SUBLIME\u3001MSVC\u3001Turbo C\u7b49\u3002
\u53c2\u8003\u8d44\u6599\uff1a\u767e\u5ea6\u767e\u79d1\u2014\u2014C\u8bed\u8a00
c语言学生成绩管理系统
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 学号 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};
typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;
void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}
void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:输入错误!\n");
}
void Nofind()
{
printf("\n=====>提示:没有找到该学生!\n");
}
void printc() /* 本函数用于输出中文 */
{
printf(" 学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\n");
}
void printe(Node *p)/* 本函数用于输出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}
Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位连表中符合要求的接点,并返回该指针 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按学号查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}
void Add(Link l) /* 增加学生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 将指针置于最末尾 */
while(1)
{
printf("请你输入学号(以'0'返回上一级菜单:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}
p=(Node *)malloc(sizeof(Node));
strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->data.name);
getchar();
printf("请你输入性别:");
scanf("%s",p->data.sex);
getchar();
printf("请你输入c语言成绩:");
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入数学成绩:");
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入英语成绩:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息输入已经完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;
}
}
void Qur(Link l) /* 查询学生 */
{
int sel;
char findmess[20];
Node *p;
if(!l->next)
{
printf("\n=====>提示:没有资料可以查询!\n");
return;
}
printf("\n=====>1按学号查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 学号 */
{
printf("请你输入要查找的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("请你输入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();
}
void Del(Link l) /* 删除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}
void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以修改!\n");
return;
}
printf("请你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("请你输入新学号(原来是%s):",p->data.num);
scanf("%s",p->data.num);
printf("请你输入新姓名(原来是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("请你输入新性别(原来是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
Nofind();
}
void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;
if(!p)
{
printf("\n=====>提示:没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}
void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:没有资料可以统计!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;
r=r->next;
}
printf("------------------------------统计结果--------------------------------\n");
printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);
printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}
void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;
ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表 */
ll->next=NULL;
if(l->next==NULL)
{
printf("\n=====>提示:没有资料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息 */
s->data=p->data;
s->next=NULL;
rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已经完成!\n");
}
void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打开文件时发生错误!\n");
exit(1);
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}
void main()
{
Link l;/* 连表 */
FILE *fp; /* 文件指针 */
int sel;
char ch;
char jian;
int count=0;
Node *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501 黄欢(32号)\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;
fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已经打开,正在导入记录......\n");
while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中 */
{
p->next=NULL;
r->next=p;
r=p; /* 将该接点挂入连中 */
count++;
}
}
fclose(fp); /* 关闭文件 */
printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);
while(1)
{
menu();
printf("请你选择操作:");
scanf("%d",&sel);
if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已经退出系统,再见!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加学生 */
case 2:Del(l);break;/* 删除学生 */
case 3:Qur(l);break;/* 查询学生 */
case 4:Modify(l);break;/* 修改学生 */
case 5:Save(l);break;/* 保存学生 */
case 9:printf("\t\t\t==========帮助信息==========\n");break;
default: Wrong();getchar();break;
}
}
}
/* */
/*
学生成绩管理程序
编制一个统计学生考试分数的管理程序。
设学生成绩已以一个学生一个记录的形式存储在文件中,
每位学生记录包含的信息有:姓名,学号和各门功课的成绩。
程序具有以下几项功能:求出各门课程的总分,平均分,按姓名,
按学号寻找其记录并显示,浏览全部学生成绩和按总分由高到低显示学生信息等。
*/
#include <stdio.h>
#define SWN 3 /* 课程数 */
#define NAMELEN 20 /* 姓名最大字符数 */
#define CODELEN 10 /* 学号最大字符数 */
#define FNAMELEN 80 /* 文件名最大字符数 */
#define BUFLEN 80 /* 缓冲区最大字符数 */
/* 课程名称表 */
char schoolwork[SWN][NAMELEN+1] = {"Chinese","Mathematic","English"};
struct record
{
char name[NAMELEN+1]; /* 姓名 */
char code[CODELEN+1]; /* 学号 */
int marks[SWN]; /* 各课程成绩 */
int total; /* 总分 */
}stu;
struct node
{
char name[NAMELEN+1]; /* 姓名 */
char code[CODELEN+1]; /* 学号 */
int marks[SWN]; /* 各课程成绩 */
int total; /* 总分 */
struct node *next; /* 后续表元指针 */
}*head; /* 链表首指针 */
int total[SWN]; /* 各课程总分 */
FILE *stfpt; /* 文件指针 */
char stuf[FNAMELEN]; /* 文件名 */
/* 从指定文件读入一个记录 */
int readrecord(FILE *fpt,struct record *rpt)
{
char buf[BUFLEN];
int i;
if(fscanf(fpt,"%s",buf)!=1)
return 0; /* 文件结束 */
strncpy(rpt->name,buf,NAMELEN);
fscanf(fpt,"%s",buf);
strncpy(rpt->code,buf,CODELEN);
for(i=0;i<SWN;i++)
fscanf(fpt,"%d",&rpt->marks[i]);
for(rpt->total=0,i=0;i<SWN;i++)
rpt->total+=rpt->marks[i];
return 1;
}
/* 对指定文件写入一个记录 */
writerecord(FILE *fpt,struct record *rpt)
{
int i;
fprintf(fpt,"%s\n",rpt->name);
fprintf(fpt,"%s\n",rpt->code);
for(i=0;i<SWN;i++)
fprintf(fpt,"%d\n",rpt->marks[i]);
return ;
}
/* 显示学生记录 */
displaystu(struct record *rpt)
{
int i;
printf("\nName : %s\n",rpt->name);
printf("Code : %s\n",rpt->code);
printf("Marks :\n");
for(i=0;i<SWN;i++)
printf(" %-15s : %4d\n",schoolwork[i],rpt->marks[i]);
printf("Total : %4d\n",rpt->total);
}
/* 计算各单科总分 */
int totalmark(char *fname)
{
FILE *fp;
struct record s;
int count,i;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
for(i=0;i<SWN;i++)
total[i]=0;
count=0;
while(readrecord(fp,&s)!=0)
{
for(i=0;i<SWN;i++)
total[i]+=s.marks[i];
count++;
}
fclose(fp);
return count; /* 返回记录数 */
}
/* 列表显示学生信息 */
void liststu(char *fname)
{
FILE *fp;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return ;
}
while(readrecord(fp,&s)!=0)
{
displaystu(&s);
printf("\n Press ENTER to continue...\n");
while(getchar()!='\n');
}
fclose(fp);
return;
}
/* 构造链表 */
struct node *makelist(char *fname)
{
FILE *fp;
struct record s;
struct node *p,*u,*v,*h;
int i;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return NULL;
}
h=NULL;
p=(struct node *)malloc(sizeof(struct node));
while(readrecord(fp,(struct record *)p)!=0)
{
v=h;
while(v&&p->total<=v->total)
{
u=v;
v=v->next;
}
if(v==h)
h=p;
else
u->next=p;
p->next=v;
p=(struct node *)malloc(sizeof(struct node));
}
free(p);
fclose(fp);
return h;
}
/* 顺序显示链表各表元 */
void displaylist(struct node *h)
{
while(h!=NULL)
{
displaystu((struct record *)h);
printf("\n Press ENTER to continue...\n");
while(getchar()!='\n');
h=h->next;
}
return;
}
/* 按学生姓名查找学生记录 */
int retrievebyn(char *fname, char *key)
{
FILE *fp;
int c;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
c=0;
while(readrecord(fp,&s)!=0)
{
if(strcmp(s.name,key)==0)
{
displaystu(&s);
c++;
}
}
fclose(fp);
if(c==0)
printf("The student %s is not in the file %s.\n",key,fname);
return 1;
}
/* 按学生学号查找学生记录 */
int retrievebyc(char *fname, char *key)
{
FILE *fp;
int c;
struct record s;
if((fp=fopen(fname,"r"))==NULL)
{
printf("Can't open file %s.\n",fname);
return 0;
}
c=0;
while(readrecord(fp,&s)!=0)
{
if(strcmp(s.code,key)==0)
{
displaystu(&s);
c++;
break;
}
}
fclose(fp);
if(c==0)
printf("The student %s is not in the file %s.\n",key,fname);
return 1;
}
main()
{
int i,j,n;
char c;
char buf[BUFLEN];
FILE *fp;
struct record s;
clrscr();
printf("Please input the students marks record file's name: ");
scanf("%s",stuf);
if((fp=fopen(stuf,"r"))==NULL)
{
printf("The file %s doesn't exit, do you want to creat it? (Y/N) ",stuf);
getchar();
c=getchar();
if(c=='Y'||c=='y')
{
fp=fopen(stuf,"w");
printf("Please input the record number you want to write to the file: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Input the student's name: ");
scanf("%s",&s.name);
printf("Input the student's code: ");
scanf("%s",&s.code);
for(j=0;j<SWN;j++)
{
printf("Input the %s mark: ",schoolwork[j]);
scanf("%d",&s.marks[j]);
}
writerecord(fp,&s);
}
fclose(fp);
}
}
fclose(fp);
getchar();
/*clrscr();*/
puts("Now you can input a command to manage the records.");
puts("m : mean of the marks.");
puts("t : total of the marks.");
puts("n : search record by student's name.");
puts("c : search record by student's code.");
puts("l : list all the records.");
puts("s : sort and list the records by the total.");
puts("q : quit!");
while(1)
{
puts("Please input command:");
scanf(" %c",&c); /* 输入选择命令 */
if(c=='q'||c=='Q')
{
puts("\n Thank you for your using.");
break; /* q,结束程序运行 */
}
switch(c)
{
case 'm': /* 计算平均分 */
case 'M':
if((n=totalmark(stuf))==0)
{
puts("Error!");
break;
}
printf("\n");
for(i=0;i<SWN;i++)
printf("%-15s's average is: %.2f.\n",schoolwork[i],(float)total[i]/n);
break;
case 't': /* 计算总分 */
case 'T':
if((n=totalmark(stuf))==0)
{
puts("Error!");
break;
}
printf("\n");
for(i=0;i<SWN;i++)
printf("%-15s's total mark is: %d.\n",schoolwork[i],total[i]);
break;
case 'n': /* 按学生的姓名寻找记录 */
case 'N':
printf("Please input the student's name you want to search: ");
scanf("%s",buf);
retrievebyn(stuf,buf);
break;
case 'c': /* 按学生的学号寻找记录 */
case 'C':
printf("Please input the student's code you want to search: ");
scanf("%s",buf);
retrievebyc(stuf,buf);
break;
case 'l': /* 列出所有学生记录 */
case 'L':
liststu(stuf);
break;
case 's': /* 按总分从高到低排列显示 */
case 'S':
if((head=makelist(stuf))!=NULL)
displaylist(head);
break;
default: break;
}
}
}
[cpp] view plaincopyprint?
<span style="font-size:16px;">#include "stdio.h"
#include"string"
/*定义学生结构体*/
struct Student
{
char ID[20];
char Name[20];
float Mark1;
float Mark2;
float Mark3;
float Average;
};
/*声明学生数组及学生数量*/
struct Student students[1000];
int num=0;
/*求平均值*/
float Avg(struct Student stu)
{
return (stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通过学号返回数组下标*/
int Student_SearchByIndex(char id[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].ID,id)==0)
{
return i;
}
}
return -1;
}
/*通过姓名返回数组下标*/
int Student_SearchByName(char name[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].Name,name)==0)
{
return i;
}
}
return -1;
}
/*显示单条学生记录*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%8s%8s%8s%10s
","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------
");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f
",students[index].ID,students[index].Name,
students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入学生信息*/
void Student_Insert()
{
while(1)
{
printf("请输入学号:");
scanf("%s",&students[num].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[num].Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num].Mark3);
getchar();
students[num].Average=Avg(students[num]);
num++;
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*修改学生信息*/
void Student_Modify()
{
//float mark1,mark2,mark3;
while(1)
{
char id[20];
int index;
printf("请输入要修改的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!
");
}
else
{
printf("你要修改的学生信息为:
");
Student_DisplaySingle(index);
printf("-- 请输入新值--
");
printf("请输入学号:");
scanf("%s",&students[index].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[index].Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index].Mark3);
getchar();
students[index].Average=Avg(students[index]);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*删除学生信息*/
void Student_Delete()
{
int i;
while(1)
{
char id[20];
int index;
printf("请输入要删除的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!
");
}
else
{
printf("你要删除的学生信息为:
");
Student_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
students[i]=students[i+1];//把后边的对象都向前移动
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按姓名查询*/
void Student_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的学生的姓名:");
scanf("%s",&name);
getchar();
index=Student_SearchByName(name);
if (index==-1)
{
printf("学生不存在!
");
}
else
{
printf("你要查询的学生信息为:
");
Student_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按平均值排序*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;i<num;i++)
{
for (j=1;j<num-i;j++)
{
if (students[j-1].Average<students[j].Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/*显示学生信息*/
void Student_Display()
{
int i;
printf("%10s%10s%8s%8s%8s%10s
","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------
");
for (i=0;i<num;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f
",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*将学生信息从文件读出*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件!
");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students[i],sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件!
");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!
");
}
for (i=0;i<num;i++)
{
if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1)
{
printf("写入文件错误!
");
}
}
fclose(fp);
}
/*主程序*/
void main()
{
int choice;
IO_ReadInfo();
while(1)
{
/*主菜单*/
printf("
------ 学生成绩管理系统------
");
printf("1. 增加学生记录
");
printf("2. 修改学生记录
");
printf("3. 删除学生记录
");
printf("4. 按姓名查询学生记录
");
printf("5. 按平均成绩排序
");
printf("6. 退出
");
printf("请选择(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
Student_Insert();
break;
case 2:
Student_Modify();
break;
case 3:
Student_Delete();
break;
case 4:
Student_Select();
break;
case 5:
Student_SortByAverage();
Student_Display();
break;
case 6:
exit(0);
break;
}
IO_WriteInfo();
}
}
</span>
太有才了
粗略看了下,上面的差不多了。
扩展阅读:扫一扫题目出答案 ... 个人成绩查询 ... c语言成绩查询官网 ... 10个学生成绩c语言 ... 学生成绩信息管理系统 ... 学生成绩管理系统python ... c语言查询学生成绩 ... c语言成绩查询入口省二 ... c语言简单成绩管理系统 ...