C言語学生情報管理システム(ダイナミックチェーン版)

14856 ワード

大学一年生の前学期の期末宿題は、長い間やっていたことしか覚えていない.コードを書く過程で、多くの問題を発見することができて、間違い、人を苦しめることができます.でも確かにたくさんのことを学びました.その中には、王瑶兄とフィフィ姉の熱心な助けがある.ありがとうございました
もちろん、今から見れば、コードには最適化できるところがたくさんあります.本プログラムの機能はまだそろっており、BUGはまだ発見されておらず、入力検出メカニズムは含まれていない.精力は有限で、その年注釈を書く習慣を身につけていないことを後悔して、今そこに置いて自分ですべて見たくなくて、==!後で機会があればC++でまた書きましょう.
図面:
コード:
/*
* C          (     )
*   :odaynot
*   :2011 
*   :      、      、      
*   :windows
*/
#include 
#include 
#include 
#include 
# define LEN sizeof(struct Student)

struct Student {
char num[10];  /*  */
char name[20]; /*  */
char sex[10];  /*  */
int age;       /*  */
char phone[12];/*  */
char qq[12];   /*QQ */
float cscore;  /*C    */
float escore;  /*    */
struct Student *next;
};

char filename[30];//    ,            

/*    */
struct Student *Creat(int n) {
	void menu_print_in(void);
	struct Student *head;
	struct Student *p1, *p2;

	system("cls");
	for(int i=1;inum,p1->name,p1->sex,
		&p1->age,p1->phone,p1->qq,&p1->cscore,&p1->escore);
		p1->next = NULL;
		if(i==1) {
			head = p2 = p1;
		}
		else {
			p2->next = p1;
			p2 = p1;
		}
	}
	return(head);
}

/*    (wb  )*/
void WriteData_wb(struct Student *head) {
	FILE *fp;
	struct Student *p;
	if((fp = fopen(filename, "wb"))==NULL)
	printf("\a error! Can not open the file!");
	p = head;
	while(p!=NULL) {
		if(fwrite(p,LEN,1,fp)!=1) {
			printf("      
"); fclose(fp); return; } p=p->next; } fclose(fp); } /* (ab )*/ void WriteData_ab(struct Student *head) { FILE *fp; struct Student *p; if((fp = fopen(filename, "ab"))==NULL) printf("\a error! Can not open the file!"); p = head; while(p!=NULL) { if(fwrite(p,LEN,1,fp)!=1) { printf("
"); fclose(fp); return; } p=p->next; } fclose(fp); } /* */ /* , */ struct Student *ReadData(void) { struct Student *head = NULL; struct Student *p1, *p2;//s = p1;p = p2; FILE *fp; if((fp=fopen(filename,"rb+"))==NULL) { printf("
"); exit(0); } while(!feof(fp)) { if((p1=(struct Student*)malloc(LEN))==NULL){ printf("
"); fclose(fp); exit(0); } if(fread(p1,LEN,1,fp)!=1){ free(p1); break; } if(head==NULL) head=p2=p1; else{ p2->next=p1; p2=p1; } } fclose(fp); return (head); } /*【1】 */ void Print_inquire_all(void) { void menu_print_out(void); struct Student *pt; pt = ReadData(); menu_print_out(); do { printf("%-10s%6s%8s%4d%13s%11s %4.1f %4.1f %4.1f %4.1f
", pt->num,pt->name,pt->sex,pt->age,pt->phone,pt->qq,pt->cscore, pt->escore,(pt->cscore+pt->escore)/2,pt->cscore+pt->escore); pt = pt->next; }while(pt!=NULL); printf("

"); } /*【2】 */ int Print_inquire_num() { void menu_print_out(void); struct Student *pt; char str_num[10]; printf("◎ :"); scanf("%s", str_num); pt = ReadData(); menu_print_out(); do { if(strcmp(pt->num,str_num)==0) { printf("%-10s%6s%8s%4d%13s%11s %4.1f %4.1f %4.1f %4.1f
", pt->num,pt->name,pt->sex,pt->age,pt->phone,pt->qq,pt->cscore, pt->escore,(pt->cscore+pt->escore)/2,pt->cscore+pt->escore); printf("

"); return 0; } pt = pt->next; }while(pt!=NULL); printf(" !
"); printf("

"); return 0; } /*【3】 */ int Print_inquire_name() { void menu_print_out(void); struct Student *pt; char str_name[20]; printf("◎ :"); scanf("%s", str_name); pt = ReadData(); menu_print_out(); do { if(strcmp(pt->name,str_name)==0) { printf("%-10s%6s%8s%4d%13s%11s %4.1f %4.1f %4.1f %4.1f
", pt->num,pt->name,pt->sex,pt->age,pt->phone,pt->qq,pt->cscore, pt->escore,(pt->cscore+pt->escore)/2,pt->cscore+pt->escore); printf("

"); return 0; } pt = pt->next; }while(pt!=NULL); printf(" !
"); printf("

"); return 0; } /*【4】 */ int Print_inquire_fuzzy(void) { void menu_print_out(void); struct Student *pt; char str_find[20]; int m = 0; printf("◎ :"); scanf("%s", str_find); pt = ReadData(); menu_print_out(); do { if(strstr(pt->num,str_find)!=0||strstr(pt->name,str_find)!=0 ||strstr(pt->sex,str_find)!=0||strstr(pt->phone,str_find)!=0 ||strstr(pt->qq,str_find)!=0) { printf("%-10s%6s%8s%4d%13s%11s %4.1f %4.1f %4.1f %4.1f
", pt->num,pt->name,pt->sex,pt->age,pt->phone,pt->qq,pt->cscore, pt->escore,(pt->cscore+pt->escore)/2,pt->cscore+pt->escore); m = 1; } pt = pt->next; }while(pt!=NULL); if(!m) printf(" !
"); printf("

"); return 0; } /* */ int Print_inquire_stats(void) { struct Student *head, *p1; float CMIN, CMAX, EMIN, EMAX, SMIN, SMAX; head = ReadData(); p1 = head; CMIN = CMAX = p1->cscore; EMIN = EMAX = p1->escore; SMIN = SMAX = p1->cscore + p1->escore; while(p1->next!=NULL) { if(p1->cscore > CMAX) { CMAX = p1->cscore; } if(p1->cscore < CMIN) { CMIN = p1->cscore; } if(p1->escore > EMAX) { EMAX = p1->escore; } if(p1->escore < EMIN) { EMIN = p1->escore; } if((p1->cscore + p1->escore) > SMAX) { SMAX = (p1->cscore + p1->escore); } if((p1->cscore + p1->escore) < SMIN) { SMIN = (p1->cscore + p1->escore); } p1 = p1->next; } printf("
"); printf("◎ C :%4.1f
", CMAX); printf("◎ C :%4.1f

", CMIN); printf("◎ :%4.1f
", EMAX); printf("◎ :%4.1f

", EMIN); printf("◎ :%4.1f
", SMAX); printf("◎ :%4.1f

", SMIN); printf("
"); printf("【PS: , O(∩_∩)O】

"); return 0; } /*【1】 */ int Delete() { struct Student *pt1, *pt2, *head; char str_num[20]; printf("
◎ :"); scanf("%s", str_num); pt1 = ReadData(); pt2 = pt1->next; head = pt1; while(pt2!=NULL) { if(strcmp(pt1->num,str_num)==0) { WriteData_wb(pt2); } else if(strcmp(pt2->num,str_num)==0) { pt1->next = pt2->next; WriteData_wb(head); } pt2 = pt2->next; pt1 = pt1->next; } if(pt2!=NULL) printf(" !
"); printf("

"); return 0; } /*【2】 */ int Amend() { void menu_print_in(void); struct Student *pt1, *pt2, *head; char str_num[20]; printf("◎ :"); scanf("%s", str_num); pt1 = ReadData(); pt2 = pt1->next; head = pt1; while(pt2!=NULL) { if(strcmp(pt1->num,str_num)==0) { menu_print_in(); scanf("%s%s%s%d%s%s%f%f",pt1->num,pt1->name,pt1->sex, &pt1->age,pt1->phone,pt1->qq,&pt1->cscore,&pt1->escore); WriteData_wb(head); } else if(strcmp(pt2->num,str_num)==0) { menu_print_in(); scanf("%s%s%s%d%s%s%f%f",pt2->num,pt2->name,pt2->sex, &pt2->age,pt2->phone,pt2->qq,&pt2->cscore,&pt2->escore); WriteData_wb(head); } pt2 = pt2->next; pt1 = pt1->next; } if(pt2!=NULL) printf(" !
"); return 0; } /*【3】 */ int Neaten() { struct Student *first; struct Student *tail; struct Student *p_min; struct Student *min; struct Student *p; struct Student *head; head = ReadData(); first = NULL; while(head!=NULL) { for(p=head,min=head; p->next!=NULL; p=p->next) { if(strcmp(p->next->num,min->num)<0) { p_min = p; min = p->next; } } if(first==NULL) { first = min; tail = min; } else { tail->next = min; tail = min; } if(min==head) { head = head->next; } else { p_min->next = min->next; } } if(first!=NULL) { tail->next = NULL; } head = first; WriteData_wb(head); return 0; } /* */ int Creat_num(void) { printf("
◎ :"); int n; if(scanf("%d", &n)!=1) { printf("\a error!"); } return n; } /* */ int File_name() { printf("
◎ :"); if(scanf("%s", filename)!=1) printf("\a error!"); return 0; } /* */ void menu(void) { void menu_add(void); void menu_inquire(void); void menu_amend(void); printf(" ╭════════╮
"); printf("╭══════╣ V1.0╠══════╮
"); printf("║ ╰════════╯ ║
"); printf("║ 【1】 【3】 ║
"); printf("║ ║
"); printf("║ 【2】 【4】 ║
"); printf("║ ║
"); printf("╰══════════════════════╯
"); printf("◎ :【 】\b\b"); int a = 0; a = getchar(); while(a!='1'&&a!='2'&&a!='3'&&a!='4') { printf("error! please input the right number!
"); putchar('\a'); getchar(); printf("◎ :【 】\b\b"); a = getchar(); } switch(a) { case '1': File_name();menu_add(); break; case '2': File_name();menu_inquire(); break; case '3': File_name();menu_amend(); break; case '4': exit(0); break; } getchar(); } /* */ void menu_add(void) { system("cls"); getchar(); printf(" ╭════════╮
"); printf("╭══════╣ ╠══════╮
"); printf("║ ╰════════╯ ║
"); printf("║ 【1】 【2】 【3】 ║
"); printf("║ ║
"); printf("╰══════════════════════╯
"); printf("◎ :【 】\b\b"); int a = 0; a = getchar(); while(a!='1'&&a!='2'&&a!='3') { printf("error! please input the right number!
"); putchar('\a'); getchar(); printf("◎ :【 】\b\b"); a = getchar(); } switch(a) { case '1': WriteData_wb(Creat(Creat_num())); printf("
◎ ◎
"); system("pause"); system("cls"); menu_add(); break; case '2': WriteData_ab(Creat(Creat_num())); printf("
◎ ◎
"); system("pause"); system("cls"); menu_add(); break; case '3': system("cls"); getchar(); menu(); break; } } /* */ void menu_inquire(void) { system("cls"); getchar(); while(1) { system("cls"); printf(" ╭════════╮
"); printf("╭══════╣ ╠══════╮
"); printf("║ ╰════════╯ ║
"); printf("║ 【1】 【4】 ║
"); printf("║ ║
"); printf("║ 【2】 【5】 ║
"); printf("║ ║
"); printf("║ 【3】 【6】 ║
"); printf("╰══════════════════════╯
"); printf("◎ :【 】\b\b"); int a = 0; a = getchar(); while(a!='1'&&a!='2'&&a!='3'&&a!='3'&&a!='4'&&a!='5'&&a!='6') { printf("error! please input the right number!
"); putchar('\a'); getchar(); printf("◎ :【 】\b\b"); a = getchar(); } switch(a) { case '1': Print_inquire_all();system("pause");getchar(); break; case '2': Print_inquire_num();system("pause");getchar(); break; case '3': Print_inquire_name();system("pause");getchar(); break; case '4': Print_inquire_fuzzy();system("pause");getchar();; break; case '5': Print_inquire_stats();system("pause");getchar(); break; case '6': system("cls");getchar();menu(); break; } } } /* */ void menu_amend(void) { system("cls"); getchar(); while(1) { system("cls"); printf(" ╭════════╮
"); printf("╭══════╣ ╠══════╮
"); printf("║ ╰════════╯ ║
"); printf("║ 【1】 【3】 ║
"); printf("║ ║
"); printf("║ 【2】 【4】 ║
"); printf("╰══════════════════════╯
"); printf("◎ :【 】\b\b"); int a = 0; a = getchar(); while(a!='1'&&a!='2'&&a!='3'&&a!='4') { printf("error! please input the right number!
"); putchar('\a'); getchar(); printf("◎ :【 】\b\b"); a = getchar(); } switch(a) { case '1': Delete(); printf("

◎ ◎
"); system("pause"); getchar(); break; case '2': Amend(); printf("

◎ ◎
"); system("pause"); getchar(); break; case '3': Neaten(); printf("

◎ ◎
"); system("pause"); getchar(); break; case '4': system("cls"); getchar(); menu(); break; } } } /* */ void menu_print_in(void) { printf("------------------------------------------------------------------------
"); printf(" QQ C E
"); printf("------------------------------------------------------------------------
"); } void menu_print_out(void) { printf("--------------------------------------------------------------------------
"); printf(" QQ C E A S
"); printf("--------------------------------------------------------------------------
"); } /* */ int main(void) { SetConsoleTitle(L"C++ "); menu(); return 0; }