| 7 | 1/1 | 返回列表 |
| 查看: 3231 | 回復: 6 | |||
[交流]
【求助】求將c語言改寫為C++,求教高人!
|
|
#include #include #include #include #define N 3 struct student { char name[10]; char no[10]; char sex; int age; char bnote[100]; }; void print(bool menu)//打印基本信息 { if (!menu) { printf("學生基本信息錄入 ,press 1\n"); } else { printf("學生基本信息顯示 ,press 2\n"); printf("學生基本信息保存 ,press 3\n"); printf("學生基本信息刪除 ,press 4\n"); printf("學生基本信息修改 ,press 5\n"); printf("學生基本信息查詢 ,press 6\n"); } printf("退出學生信息系統(tǒng) ,press 7\n"); } bool Check(char pas[6])//密碼驗證 { FILE *fp; char ch; char a[7]={" "}; int i = 0; if ((fp=fopen("c:\\1.txt","r"))==NULL) { printf("打開文件失敗!\n"); exit(0); } ch=fgetc(fp); while (ch!=EOF&&i<6) { a = ch; ch=fgetc(fp); i++; } a[6] = '\0'; if (!strcmp(pas,a)) { return true; } else { printf("密碼錯誤\n"); return false; } fclose(fp); } void GetInfo(struct student *arr,int n)//學生基本信息錄入 { for (int i = 0;i printf("輸入學生的基本信息:name no sex age bnote\n"); scanf("%s %s %c %d %s",arr.name,arr.no,&arr.sex,&arr.age,arr.bnote); } } void Display(struct student* arr,int n)//學生基本信息顯示 { printf("學生信息: Name NO Sex age Note\n"); for (int i = 0;i printf("%15s%15s%15c%15d%15s\n",arr.name,arr.no,arr.sex,arr.age,arr.bnote); } } void Save(struct student* arr,int n)//學生基本信息保存,保存在c:\\student.txt { FILE * fp; fp= fopen("c:\\student.txt","w+"); if (fp == NULL) { printf("文件不存在!\n"); exit(0); } fwrite(arr,sizeof(struct student)*n,n,fp); fclose(fp); } void Modfiy(struct student* arr,int n)//學生基本信息修改 { char number[10]; bool flag=false; char pass[6]; printf("請輸入密碼:\n"); scanf("%s",pass); if (Check(pass)) { printf("修改學生信息:\n"); printf("請輸入學號:\n"); scanf("%s",number); for (int i =0;i if (!strcmp(number,arr.no)) { printf("infor: name no sex age note\n"); printf("%12s%12s%12c%12d%12s\n",arr.name,arr.no, arr.sex,arr.age,arr.bnote); printf("please input information:\n"); scanf("%s%s%c%d%s",arr.name,arr.no,&arr.sex,&arr.age,arr.bnote); Save(arr,n); flag = true; } } if (flag == false) { printf("該學生不存在!:\n"); } } } void Delete(struct student* arr,int n)//學生基本信息刪除 { char number[10]; bool flag=false; printf("Delete information:\n"); printf("please input the no:\n"); scanf("%s",number); for (int i =0;i if (!strcmp(number,arr.no)) { strcpy(arr.name," "); strcpy(arr.no," "); strcpy(arr.bnote," "); arr.sex = ' '; arr.age = 0; Save(arr,n); flag = true; } } if (flag == true) { printf("該學生不存在!:\n"); } } void Search(struct student* arr,int n)//學生基本信息查詢 { int temp,i; bool flag=false; printf("---------------通過學號查詢,press 1-------------\n"); printf("---------------通過姓名查詢,press 2-----------\n"); printf("---------------通過性別查詢,press 3------------\n"); printf("---------------通過年齡查詢,press 4------------\n"); printf("---------------退出,press 5 ------------\n"); scanf("%d",&temp); switch (temp) { case 1://按照學號查詢 { char num[10]; printf("請輸入學號:\n"); scanf("%s",num); for ( i =0;i if (!strcmp(num,arr.no)) { printf("%12s%12s%12c%12d%12s\n",arr.name,arr.no, arr.sex,arr.age,arr.bnote); flag = true; } } if (!flag) { printf("該學生不存在.\n"); } } break; case 2://按照名字查詢 { char num[10]; printf("please input name:\n"); scanf("%s",num); for ( i =0;i if (!strcmp(num,arr.name)) { printf("%12s%12s%12c%12d%12s",arr.name,arr.no, arr.sex,arr.age,arr.bnote); flag = true; } } if (!flag) { printf("該學生不存在.\n"); } } break; case 3://按照性別查詢 { char ch; printf("請輸入性別:\n"); //scanf("%c",&ch); ch = getch(); for ( i =0;i if (ch == arr.sex) { printf("%12s%12s%12c%12d%12s\n",arr.name,arr.no, arr.sex,arr.age,arr.bnote); flag = true; } } if (!flag) { printf("t該學生不存在.\n"); } } break; case 4://按照年齡查詢 { char num_age; printf("請輸入年齡:\n"); scanf("%d",&num_age); for ( i =0;i if (num_age == arr.age) { printf("%12s%12s%12c%12d%12s\n",arr.name,arr.no, arr.sex,arr.age,arr.bnote); flag = true; } } if (!flag) { printf("該學生不存在.\n"); } } break; default: break; } } void main() { struct student arr[N]; char ps[6]; bool flag =false; printf("請輸入密碼:\n"); scanf("%s",ps); flag = Check(ps); if (flag) { int select; print(false); scanf("%d",&select); while (0 { switch (select) { case 1: GetInfo(arr,N); print(true); break; case 2: Display(arr,N); print(true); break; case 3: Save(arr,N); print(true); break; case 4: Delete(arr,N); print(true); break; case 5: Modfiy(arr,N); print(true); break; case 6: Search(arr,N); print(true); break; default: break; } printf("請選擇:\n"); scanf("%d",&select); } } } |
至尊木蟲 (文壇精英)
銀蟲 (小有名氣)


銀蟲 (小有名氣)


| 7 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 085601專碩,總分342求調(diào)劑,地區(qū)不限 +3 | share_joy 2026-03-16 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 化學調(diào)劑0703 +8 | 啊我我的 2026-03-11 | 8/400 |
|
|
[考研] 0703一志愿211 285分求調(diào)劑 +5 | ly3471z 2026-03-13 | 5/250 |
|
|
[考研]
|
笨笨兔子 2026-03-12 | 3/150 |
|
|
[考研] 本科南京大學一志愿川大藥學327 +3 | 麥田耕者 2026-03-14 | 3/150 |
|
|
[考研] 材料與化工 323 英一+數(shù)二+物化,一志愿:哈工大 本人本科雙一流 +4 | 自由的_飛翔 2026-03-13 | 5/250 |
|
|
[考研] 中科大材料專碩319求調(diào)劑 +3 | 孟鑫材料 2026-03-13 | 3/150 |
|
|
[考研] 308 085701 四六級已過求調(diào)劑 +7 | 溫喬喬喬喬 2026-03-12 | 14/700 |
|
|
[考研] 279求調(diào)劑 +3 | 抓著星星的女孩 2026-03-10 | 3/150 |
|
|
[考研] 341求調(diào)劑 +3 | 番茄頭--- 2026-03-10 | 3/150 |
|
|
[考研] 304求調(diào)劑 +6 | Mochaaaa 2026-03-12 | 7/350 |
|
|
[考研] [0860]321分求調(diào)劑,ab區(qū)皆可 +4 | 寶貴熱 2026-03-13 | 4/200 |
|
|
[考研] 0856材料與化工301求調(diào)劑 +5 | 奕束光 2026-03-13 | 5/250 |
|
|
[考研] 工科,求調(diào)劑 +3 | 我887 2026-03-11 | 3/150 |
|
|
[考研] 材料工程調(diào)劑 +4 | 咪咪空空 2026-03-11 | 4/200 |
|
|
[考研] 求b區(qū)學校調(diào)劑 +3 | 周56 2026-03-11 | 3/150 |
|
|
[考研] 求調(diào)劑 +7 | 18880831720 2026-03-11 | 7/350 |
|
|
[考研] 土木第一志愿276求調(diào)劑,科研和技能十分豐富,求新興方向的導師收留 +3 | 土木小天才 2026-03-12 | 3/150 |
|
|
[考研] 070303一志愿西北大學學碩310找調(diào)劑 +3 | d如愿上岸 2026-03-13 | 3/150 |
|
|
[考研] 求調(diào)劑 資源與環(huán)境 285 +3 | 未名考生 2026-03-10 | 3/150 |
|