C語言之學(xué)生檔案管理_第1頁
C語言之學(xué)生檔案管理_第2頁
免費(fèi)預(yù)覽已結(jié)束,剩余8頁可下載查看

下載本文檔

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

文檔簡介

1、/*#include#include#include #include#define MAX 500 /定義儲存容量typedef structint month,day,year。/出生年月BD。typedef structint number。/學(xué)號char name13。/姓名char sex7。/性別:male or femaleBD birth。/出生年月MM-DD-YYchar addr35。/地址ST。ST studentMAX。/全局變量/*函數(shù)聲明*/void menu_show()。/顯示菜單void menu()。/菜單響應(yīng)char get_menu_choice()。/

2、獲取菜單選擇信息FILE*file_operate(char*mode)。/文件操作模塊voidadd(FILE*fp)。/添加學(xué)生信息void show(FILE*fp)。/顯示學(xué)生信息void search(FILE*fp)。/查找學(xué)生信息void modify(FILE*fp)。/修改學(xué)生信息void del(FILE*fp)。/刪除學(xué)生信息voidf_backup()。/文件備份void psw_check()。/密碼驗(yàn)證voidset_psw()。/設(shè)置密碼int main()system(cls)。psw_check()。menu()。return 0。/* voidmenu_sh

3、ow()printf(nn)。一葉星塵S歡*主函數(shù)*顯示菜單*void menu()while(1)menu_show()。switch(get_menu_choice()case 1:add(file_operate(a)。system(pause)。system(cls)。break。case 2:show(file_operate(rb)。system(pause)。system(cls)。break。case3:search(file_operate(rb)。system(pause)。system(cls)。break。case 4:modify(file_operate(rb)。s

4、ystem(pause)。system(cls)。break。case 5:del(file_operate(r)。system(pause)。system(cls)。break。case 6:f_backup()。system(pause)。system(cls)。break。case 7:set_psw()。system(pause)。system(cls)。printf(t+- - +n)。printf(t|學(xué)生檔案管理系統(tǒng)|n)。printf(t|-|n)。printf(t|【1.輸入數(shù)據(jù)】|【5.刪除數(shù)據(jù)】|n)。printf(t|【2.顯示數(shù)據(jù)】|【6.備份數(shù)據(jù)】|n)。print

5、f(t|【3.查詢數(shù)據(jù)】|【7.設(shè)置口令】|n)。printf(t|【4.修改數(shù)據(jù)】|【0.退出 】|n)。printf(t+- +n)。*菜單響應(yīng)模塊*break。case 0:printf(Thank you for use this program.n)。system(pause)。system(cls)。exit(0)。/正常退出char get_menu_choice()char menu_choice。dofflush(stdin)。printf(Pleasechoice:)。scanf(%c,&menu_choice)。if(menu_choice7)puts(input

6、error,try again.)。while(menu_choice7)。return menu_choice。FILE*file_operate(char*mode)char choise。FILE*fp。dofflush(stdin)。if(fp=fopen(d:student,mode)=NULL) /打開文件puts(File operation failure)。puts(Try Again(y/n)?)。scanf(%c,&choise)。while(choise=y|choise=Y)。if(choise=n|choise=N)exit(1)。/非正常退出return

7、fp。void add(FILE*fp)*接收菜單選擇*文件操作*輸入資料*int i=0。char choice=y。doprintf(No.(11101040221): )。scanf(%d,&studenti.number)。printf(Name(less than 12character): )。scanf(%s,&)。printf(Sex(maleor female): )。scanf(%s,&studenti.sex)。printf(Birthday:n)。printf( year:)。scanf(%d,&studenti

8、.birth.year)。printf( month:)。scanf(%d,&studenti.birth.month)。printf( day:)。scanf(%d,&studenti.birth.day)。printf(Address: )。scanf(%s,studenti.addr)。if(fwrite(&studenti,sizeof(ST),1,fp)!=1) puts(data write error.)。i+。fflush(stdin)。printf(Continue(y/n)?)。scanf(%c,&choice)。while(choice=y

9、|choice=Y)。fclose(fp)。void search(FILE*fp)int i,m。char search_name20。/查找姓名變量char choice=y。for(i=0。feof(fp)=0。i+) /讀取文件if(fread(&studenti,sizeof(ST),1,fp)!=1&feof(fp)=0) puts(error)。m=i-1。/m被賦值為數(shù)組非空數(shù)據(jù)最大索引值dofflush(stdin)。puts(Enter the name for searching: )。*查找信息*gets(search_name)。for(i=0。im。

10、i+) /遍歷數(shù)組if(strcmp(search_name,)=0) /判斷是否有要查找的學(xué)生姓名,有則顯示數(shù)據(jù)printf(No.:%d Name: %s Sex: %s Birth:%d-%d-%dAddress:%sn,studenti.number,,studenti.sex,studenti.birth.year,studenti.birth.month,studenti.birth.day,studenti.addr)if(feof(fp)!=0)puts(searching done.)。puts(continue(y/n)?

11、)。scanf(%c,&choice)。while(choice=y|choice=Y)。fclose(fp)。void show(FILE*fp)int i,m。for(i=0。feof(fp)=0。i+)if(fread(&studenti,sizeof(ST),1,fp)!=1&feof(fp)=0)puts(error)。m=i-1。printf(There %d Record:n,m)。printf(Number Name Sex Birth Addressn)。for(i=0。im。i+)printf(%-8d%-12s%-6s%-4d-%-2d-%-2d3

12、5sn,studenti.number,,studenti.sex,studenti.birth.year,studenti.birth.month,studenti.birth.day,studenti.addr)if(feof(fp)!=0)*顯示資料*%-puts(Display Informtion Done.)。fclose(fp)。void modify(FILE*fp)int number_temp。char i,m,j=0。FILE*fp_update。for(i=0。feof(fp)=0。i+) /讀取文件if(fread(&a

13、mp;studenti,sizeof(ST),1,fp)!=1&feof(fp)=0) puts(error)。m=i-1。dofflush(stdin)。printf(Enter number for change: )。scanf(%d,&number_temp)。for(i=0。im。i+)if(number_temp=studenti.number)j=i。printf(No.: %d Name: %s Sex: %s birth:Address:%sn,studenti.number,,studenti.sex,studenti.birth.

14、year,studenti.birth.month,studenti.birth.day,studenti.addr)if(j=0)puts(No this record.)。break。fflush(stdin)。printf(change data %d(y/n)?,number_temp)。/修改確認(rèn)scanf(%c,&choice)。if(choice=n|choice=N) /修改資料continue。printf(No.: )。scanf(%d,&studentj.number)。printf(Name:)。scanf(%s,)。print

15、f(Sex: )。*修改資料*%d-%d-%dscanf(%s,studentj.sex)。printf(Birthday: )。printf( year:)。scanf(%d,&studentj.birth.year)。printf( month: )。scanf(%d,&studentj.birth.month)。printf( day: )。scanf(%d,&studentj.birth.day)。printf(Address: )。scanf(%s,studentj.addr)。fflush(stdin)。printf(continue(y/n)?)。scan

16、f(%c,&choice)。while(choice=y|choice=Y)。fp_update=file_operate(w)。for(i=0。im。i+)if(fwrite(&studenti,sizeof(ST),1,fp_update)!=1)puts(updateerror.)。puts(changedone.)。fclose(fp_update)。void del(FILE*fp)int i,m,t=-1。int number_temp。char choice=y。for(i=0。feof(fp)=0。i+)if(fread(&studenti,sizeof

17、(ST),1,fp)!=1&feof(fp)=0) puts(error)。m=i-2。dofflush(stdin)。printf(Enter the number for delete: )。scanf(%d,&number_temp)。for(i=0。im+1。i+)if(studenti.number=number_temp) /刪除前顯示學(xué)生資料printf(No.: %d Name: %s Sex: %s Brith: Address:%sn,studenti.number,,*刪除資料*%d-%d-%dstudenti.sex,stude

18、nti.birth.year,studenti.birth.month,studenti.birth.day,studenti.advoid f_backup()FILE*fp,*fp_bak。char ch。char filename312。/存放備份文件文件名printf(Enter the backup file name:)。scanf(%s,filename)。fp=file_operate(rb)。fp_bak=fp。if(fp_bak=fopen(filename,wb)=NULL)puts(backup file error.)。exit(0)。dr)。fflush(stdin

19、)。printf(delete %d(y/n)?)。scanf(%c,&choice)。if(choice=n|choice=N) break。for(t=i。tm。t+)studentt=studentt+1。puts(delete data done.)。m-。if(t=-1&choice!=n&choice!=N)printf(No %ds data!n,number_temp)。/刪除數(shù)據(jù)fflush(stdin)。printf(continue(y/n)?)。scanf(%c,&choice)。while(choice=y|choice=Y)。fclo

20、se(fp)。fp=file_operate(w)。for(i=0。im+1。i+)if(fwrite(&studenti,sizeof(ST),1,fp)!=1)puts(error)。fclose(fp)。*文件備份*while(!feof(fp)ch=fgetc(fp)。fputc(ch,fp_bak)。fclose(fp)。fclose(fp_bak)。puts(file backup success.)。void psw_check()char psw8,psw_ i,leap。FILE*fp。if(fp=fopen(d:sn.txt,rt)=NULL) /讀取密碼,如不成功則要求設(shè)置密碼puts(You must set password first.)。menu()。if(fread(psw,sizeof(psw),1,fp)!=1) puts(error.)。for(i=0。i8。i+) /解密pswi=pswi。doleap=

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論