C語言編寫學(xué)生管理系統(tǒng)的代碼_第1頁
C語言編寫學(xué)生管理系統(tǒng)的代碼_第2頁
C語言編寫學(xué)生管理系統(tǒng)的代碼_第3頁
C語言編寫學(xué)生管理系統(tǒng)的代碼_第4頁
C語言編寫學(xué)生管理系統(tǒng)的代碼_第5頁
已閱讀5頁,還剩3頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#include<conio.h>struct student char number21;char name21; int age;char sex3; char birthday8;studentArray100;typedef struct student student;student studentArray100;char putout512="學(xué)號","

2、姓名","年齡","性別","出生年月" /為格式化輸出做準(zhǔn)備int count=0;/函數(shù)聲明部分void explain();void readfile();void searchStudent();void modifyStudent();void addStudent();void delStudent();void printAllstudent();void save();void quit();void initial();void initial()FILE *fp;char choice='y

3、9;int i=0;fp=fopen("e:students.txt","r");if(!fp)printf("創(chuàng)建文件失敗,即將返回n");return ;for(;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+);count=i;/0、說明模塊void explain()printf("n 很高興能為您服務(wù)n");printf("n1.進入本系統(tǒng),請先刷新學(xué)生信息,再查訓(xùn)n");printf("n2.您可以根據(jù)

4、自己需要的信息鍵入菜單上的編號n");printf("n3.修改學(xué)生信息后記得退出前保存信息,以免信息流失n");printf("n4.在各個子菜單里按提示操作n");printf("n5.謝謝您的使用及支持n");/1、刷新模塊void readfile() char *p="students.txt" FILE *fp; int i=0; if(fp=fopen("students.txt","r")=NULL) printf("打開文件%s出錯!請按

5、按任意鍵返回",p); system("pause"); return ; while(fscanf(fp,"%s %s %d %s %s",&studentArrayi.number,&studentA,&studentArrayi.age,&studentArrayi.sex,&studentArrayi.birthday)=5) i+; i=i; fclose(fp); printf("刷新完畢。n"); /2、查詢模塊void searchStudent()

6、 int i;int jb; FILE *fp;char studentNumber21;char studentName21;int flag=0;fp=fopen("e:students.txt","rb");if(count=0)printf("文件中還沒有學(xué)生記錄,請繼續(xù)其他操作nn");return ;printf("1.按學(xué)號查詢n"); printf("2.按姓名查詢n");printf("3.不查詢,退出n");while(1) printf("請選

7、擇子菜單編號:"); scanf("%d",&jb); flag=0; switch(jb) case 1: printf("請輸入要查詢的學(xué)生的學(xué)號:n"); scanf("%s",&studentNumber); for(i=0;i<=count;i+)if(strcmp(studentNumber,studentArrayi.number)=0) flag=1;printf("要查找的學(xué)生相關(guān)信息如下:n");printf("學(xué)號 姓名 年齡 性別 出生年月n&quo

8、t;);printf("%s %8s %7d %4s %8sn",studentArrayi.number,studentA,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday);printf("n");printf("n");if(flag=0)printf("沒有找到學(xué)號為%s的學(xué)生n", studentNumber);printf("n");return ;return ;case 2: printf(&

9、quot;請輸入要查詢的學(xué)生的姓名:n"); fflush(stdin);scanf("%s",&studentName);for(i=0;i<=count;i+) if(strcmp(studentA,studentName)=0) flag=1;printf("要查找的學(xué)生相關(guān)信息如下:n");printf("學(xué)號 姓名 年齡 性別 出生年月n");printf("%s %8s %7d %4s %8sn",studentArrayi.number,studentArr

10、,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday);printf("n");printf("n");if(flag=0)printf("沒有找到名字為%s的學(xué)生n", studentName);printf("n");return ;case 3:return;/3、修改模塊void modifyStudent()FILE *fp,*fp2;int flag=0;int i;int a,n;char studentNumber21

11、;/char c;student newdata;fp=fopen("e:students.txt","rb");if(count=0)printf("文件中還沒有學(xué)生信息,即將退出nn");return ;fp2=fopen("e:test.txt","wb");if(!fp2)printf("文件創(chuàng)建失敗,即將返回n"); return ;printf("輸入要修改的學(xué)生的學(xué)號n");fflush(stdin);scanf("%s"

12、,&studentNumber);for(n=0;n<=count;n+)if(strcmp(studentArrayn.number,studentNumber)=0)a=n;for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+)if(!strcmp(studentArrayi.number,studentNumber)flag=1;printf("將要要修改的學(xué)生信息:n");printf("%s %8s %7d %4s %8sn",studentArra

13、ya.number,studentA,studentArraya.age,studentArraya.sex,studentArraya.birthday);printf("輸入要修改后學(xué)生的學(xué)號、姓名、年齡、性別、出生年月,中間以空格隔開,回車鍵結(jié)束n");printf(" (學(xué)號格式:001) (出生年月格式:1995-03) n");fflush(stdin);scanf("%s%s%d%s%s",&newdata.number,&,&newdata.age,&

14、amp;newdata.sex,&newdata.birthday);fwrite(&newdata,sizeof(struct student),1,fp2);elsefwrite(&studentArrayi,sizeof(struct student),1,fp2);if(flag=0)printf("沒有此人,即將退出nn");return ;fclose(fp);fclose(fp2);fp=fopen("e:students.txt","wb");fp2=fopen("e:test.txt

15、","rb");for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeof(struct student),1,fp); printf("nn");fclose(fp);fclose(fp2);printf("已成功修改該學(xué)生信息。n");/4、添加模塊void addStudent() FILE *fp;char choice='y'int i=0;fp=fopen

16、("e:students.txt","ab");if(!fp)printf("創(chuàng)建文件失敗,即將返回nn");return ;while(choice='y')printf("輸入學(xué)生學(xué)號、 姓名、年齡、性別、出生年月,中間以空格隔開,以回車鍵結(jié)束n");printf(" (學(xué)號格式:001) (出生年月格式:1995-03) n");fflush(stdin);scanf("%s%s%d%s%s",&studentArrayi.number,&

17、;studentA,&studentArrayi.age,&studentArrayi.sex,&studentArrayi.birthday);fwrite(&studentArrayi,sizeof(struct student),1,fp); /將數(shù)據(jù)寫入文件中i+;count+;printf("是否繼續(xù)輸入,繼續(xù)輸入輸入y,其它值退出n");fflush(stdin);choice=getchar();choice=tolower(choice);fflush(stdin); /清空緩存輸入流fclose(fp);

18、printf("輸入任意鍵繼續(xù)nn");getch();return ;/5、刪除模塊void delStudent() FILE *fp ,*fp2;int i;char choice;int flag1=1;int flag2=0; int found=0; /用來標(biāo)記文件中是否含有此人 char studentNumber21;char studentName21;fp=fopen("e:students.txt","rb");if(count=0)printf("文件中沒有信息,即將退出nn");/getc

19、h();return ;fp2=fopen("e:test.txt","wb");if(!fp2)printf("文件創(chuàng)建失敗,即將退出n");return;printf("n");printf("1. 按照學(xué)號刪除學(xué)生信息n");printf("2. 按照名字刪除學(xué)生信息n");printf("3. 刪除所有學(xué)生信息n");printf("n");printf(" 請選擇菜單編號:");i=0;found=0;sc

20、anf("%d",&flag2);fflush(stdin);if(flag2=1)printf("輸入要刪除的學(xué)生的學(xué)號,按回車鍵結(jié)束n");scanf("%s",studentNumber);for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+) /將其他人信息轉(zhuǎn)移到test.txt文件中if(strcmp(studentArrayi.number,studentNumber)fwrite(&studentArrayi,sizeof(

21、struct student),1,fp2);elsefound=1;fclose(fp);fclose(fp2);fflush(stdin);if(found=1)printf("是否確認刪除學(xué)號為%s該學(xué)生信息,確認刪除,輸入y:n",studentNumber);elseprintf("沒有此人信息,即將退出n");return ;choice=getchar();if(choice='y') /將文件結(jié)構(gòu)指針重新定向count-;fp=fopen("e:students.txt","wb")

22、;fp2=fopen("e:test.txt","rb");for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeof(struct student),1,fp);fclose(fp);fclose(fp2);else if(flag2=0)printf("輸入要刪除的學(xué)生的名字,按回車鍵結(jié)束n");scanf("%s",studentName);for(i=0;fread

23、(&studentArrayi,sizeof(struct student),1,fp)!=0;i+) /將其他人信息轉(zhuǎn)移到test.txt文件中if(strcmp(studentA,studentName)fwrite(&studentArrayi,sizeof(struct student),1,fp2);else found=1;fclose(fp);fclose(fp2);fflush(stdin);if(found=1)printf("是否確認刪除名字為%s的該學(xué)生信息,確認刪除,輸入y:",studentName);elsep

24、rintf("沒有此人信息,即將退出nn");return;choice=getchar();if(choice='y') /將文件結(jié)構(gòu)指針重新定向count-;fp=fopen("e:students.txt","wb");fp2=fopen("e:test.txt","rb");for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeo

25、f(struct student),1,fp);fclose(fp);fclose(fp2); else if(flag2=3)char ch;printf("你確認刪除所有學(xué)生記錄嗎?繼續(xù)輸入y,停止輸入其他n");fflush(stdin);ch=getchar();if(ch='y')fp=fopen("e:students.txt","wb");count=0;printf("已刪除所有學(xué)生記錄n");return ;elseprintf("輸入錯誤n");/6、顯示模塊

26、void printAllstudent() FILE *fp;int i; fp=fopen("e:students.txt","rb");if(count=0)printf("文件中還沒有學(xué)生信息,即將退出nn");return;printf("有%d各學(xué)生的信息如下:n",count); printf("學(xué)生學(xué)號 學(xué)生姓名 年齡 性別 出生年月 n"); for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+)

27、 printf("%6s %9s %7d %5s %9sn",studentArrayi.number,studentA,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday); return;/7、保存模塊void save() int i; FILE *fp; fp=fopen("students.txt","w"); for(i=0;i<count;i+) fprintf(fp,"%s %s %d %s %s n",st

28、udentArrayi.number,studentA,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday); fclose(fp); /8、退出模塊void quit() printf("*n");printf("* *n");printf("* 謝謝使用! *n");printf("* 再見! *n");printf("* *n");printf("*n");/菜單模塊int menuselect()int choice;doprintf(" 歡迎進入學(xué)生信息管理系統(tǒng) n");printf(" n");printf(" *系統(tǒng)功能菜單*n");printf(" + +n");printf(" * 友情提示:查詢前請先刷新系統(tǒng) *n");printf(" + - - +n");printf(" * * *n");printf(&quo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論