




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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="學號","
2、姓名","年齡","性別","出生年月" /為格式化輸出做準備int count=0;/函數聲明部分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("創建文件失敗,即將返回n");return ;for(;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+);count=i;/0、說明模塊void explain()printf("n 很高興能為您服務n");printf("n1.進入本系統,請先刷新學生信息,再查訓n");printf("n2.您可以根據
4、自己需要的信息鍵入菜單上的編號n");printf("n3.修改學生信息后記得退出前保存信息,以免信息流失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("文件中還沒有學生記錄,請繼續其他操作nn");return ;printf("1.按學號查詢n"); printf("2.按姓名查詢n");printf("3.不查詢,退出n");while(1) printf("請選
7、擇子菜單編號:"); scanf("%d",&jb); flag=0; switch(jb) case 1: printf("請輸入要查詢的學生的學號:n"); scanf("%s",&studentNumber); for(i=0;i<=count;i+)if(strcmp(studentNumber,studentArrayi.number)=0) flag=1;printf("要查找的學生相關信息如下:n");printf("學號 姓名 年齡 性別 出生年月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("沒有找到學號為%s的學生n", studentNumber);printf("n");return ;return ;case 2: printf(&
9、quot;請輸入要查詢的學生的姓名:n"); fflush(stdin);scanf("%s",&studentName);for(i=0;i<=count;i+) if(strcmp(studentA,studentName)=0) flag=1;printf("要查找的學生相關信息如下:n");printf("學號 姓名 年齡 性別 出生年月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的學生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("文件中還沒有學生信息,即將退出nn");return ;fp2=fopen("e:test.txt","wb");if(!fp2)printf("文件創建失敗,即將返回n"); return ;printf("輸入要修改的學生的學號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("將要要修改的學生信息:n");printf("%s %8s %7d %4s %8sn",studentArra
13、ya.number,studentA,studentArraya.age,studentArraya.sex,studentArraya.birthday);printf("輸入要修改后學生的學號、姓名、年齡、性別、出生年月,中間以空格隔開,回車鍵結束n");printf(" (學號格式: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("已成功修改該學生信息。n");/4、添加模塊void addStudent() FILE *fp;char choice='y'int i=0;fp=fopen
16、("e:students.txt","ab");if(!fp)printf("創建文件失敗,即將返回nn");return ;while(choice='y')printf("輸入學生學號、 姓名、年齡、性別、出生年月,中間以空格隔開,以回車鍵結束n");printf(" (學號格式: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); /將數據寫入文件中i+;count+;printf("是否繼續輸入,繼續輸入輸入y,其它值退出n");fflush(stdin);choice=getchar();choice=tolower(choice);fflush(stdin); /清空緩存輸入流fclose(fp);
18、printf("輸入任意鍵繼續nn");getch();return ;/5、刪除模塊void delStudent() FILE *fp ,*fp2;int i;char choice;int flag1=1;int flag2=0; int found=0; /用來標記文件中是否含有此人 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("文件創建失敗,即將退出n");return;printf("n");printf("1. 按照學號刪除學生信息n");printf("2. 按照名字刪除學生信息n");printf("3. 刪除所有學生信息n");printf("n");printf(" 請選擇菜單編號:");i=0;found=0;sc
20、anf("%d",&flag2);fflush(stdin);if(flag2=1)printf("輸入要刪除的學生的學號,按回車鍵結束n");scanf("%s",studentNumber);for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+) /將其他人信息轉移到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("是否確認刪除學號為%s該學生信息,確認刪除,輸入y:n",studentNumber);elseprintf("沒有此人信息,即將退出n");return ;choice=getchar();if(choice='y') /將文件結構指針重新定向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("輸入要刪除的學生的名字,按回車鍵結束n");scanf("%s",studentName);for(i=0;fread
23、(&studentArrayi,sizeof(struct student),1,fp)!=0;i+) /將其他人信息轉移到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的該學生信息,確認刪除,輸入y:",studentName);elsep
24、rintf("沒有此人信息,即將退出nn");return;choice=getchar();if(choice='y') /將文件結構指針重新定向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("你確認刪除所有學生記錄嗎?繼續輸入y,停止輸入其他n");fflush(stdin);ch=getchar();if(ch='y')fp=fopen("e:students.txt","wb");count=0;printf("已刪除所有學生記錄n");return ;elseprintf("輸入錯誤n");/6、顯示模塊
26、void printAllstudent() FILE *fp;int i; fp=fopen("e:students.txt","rb");if(count=0)printf("文件中還沒有學生信息,即將退出nn");return;printf("有%d各學生的信息如下:n",count); printf("學生學號 學生姓名 年齡 性別 出生年月 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(" 歡迎進入學生信息管理系統 n");printf(" n");printf(" *系統功能菜單*n");printf(" + +n");printf(" * 友情提示:查詢前請先刷新系統 *n");printf(" + - - +n");printf(" * * *n");printf(&quo
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高中校園手工制作活動對學生科學探究能力的培養策略論文
- 芯片出入庫管理制度
- 茶文化創業計劃書
- 《一年級下冊語文園地五》課件
- 高二人教版高中英語模塊56有效課型課堂教學設計及案例分析鄭秋秋
- vivo智能手機營銷策劃案
- 財產分割協議書
- 湖南省2025年初中學業水平考試6月份中考模擬試卷歷史試題 (含答案)
- 北師大小學數學(2024)三年級上冊第三單元 綜合素養測評A卷(含答案)
- 2025年甘肅省隴南市九年級中考三模生物試題
- 2025年會考地理考試試題及答案
- 皮爾遜Ⅲ型曲線的離均系數Φ值表完整版
- 2025(統編版)語文二年級下冊第六單元解析+任務目標+大單元教學設計
- 《直升機介紹》課件
- 醫院預防職務犯罪講座
- 吸脂術護理查房
- 國家開放大學《幼兒園課程與活動設計》期末大作業參考答案
- 2024年中英城市更新白皮書
- NB/T 11127-2023在用鋼絲繩芯輸送帶報廢檢測技術規范
- 鐵路網絡安全概述
- 南京信息工程大學《數據庫原理與應用Ⅱ》2022-2023學年期末試卷
評論
0/150
提交評論