學生信息管理系統

来源:https://www.cnblogs.com/QLYSG/archive/2020/01/04/12150359.html
-Advertisement-
Play Games

1 #include"stdio.h" 2 #include"stdlib.h" 3 #include"string.h" 4 #include"conio.h" 5 typedef struct node 6 { 7 char xh[11]; //學號 8 char xm[10]; //姓名 9 ...


  1 #include"stdio.h"
  2 #include"stdlib.h"
  3 #include"string.h"
  4 #include"conio.h" 
  5 typedef struct node
  6 {
  7     char xh[11];    //學號
  8     char xm[10];    //姓名
  9     char xb[3];        //性別
 10     int nl;            //年齡
 11     char dh[12];    //電話
 12     char jg[30];    //籍貫
 13     float rxcj;        //成績
 14 }student;
 15 int menu();
 16 void add();
 17 void display();
 18 void dele();
 19 void sort();
 20 void update();
 21 void search();
 22 
 23 int menu()
 24 {
 25     system("cls");
 26     char ch[2]; int num1;
 27     printf("學生信息管理系統\n");
 28     printf("---------------------\n");
 29     printf("1.學生信息錄入\n");
 30     printf("2.學生信息顯示\n");
 31     printf("3.學生信息查詢\n");
 32     printf("4.學生信息排序\n");
 33     printf("5.學生信息刪除\n");
 34     printf("6.學生信息修改\n");
 35     printf("0.退出管理系統\n");
 36     printf("---------------------\n");
 37     printf("請輸入你的選擇: ");
 38     //fflush(stdin);
 39     gets_s(ch);
 40     num1 = atoi(ch);   //將字元串轉化為int型的數字
 41     return num1;
 42 }
 43 void add()
 44 {
 45     student stu;
 46     FILE *fp;
 47     if ((fp = fopen("學生基本信息.txt", "a")) == NULL)
 48     {
 49         printf("打開文件失敗!");
 50     }
 51     
 52     printf("請輸入學生的學號:");
 53     scanf("%s", stu.xh);
 54     printf("請輸入學生的姓名:");
 55     scanf("%s", stu.xm);
 56     printf("請輸入學生的性別:");
 57     scanf("%s", stu.xb);
 58     printf("請輸入學生的年齡:");
 59     scanf("%d", &stu.nl);
 60     printf("請輸入學生的電話:");
 61     scanf("%s", stu.dh);
 62     printf("請輸入學生的籍貫:");
 63     scanf("%s", stu.jg);
 64     printf("請輸入學生的成績:");
 65     scanf("%f", &stu.rxcj);
 66     fwrite(&stu, sizeof(student), 1, fp);
 67     fclose(fp);
 68     //fflush(stdin);
 69     getchar();
 70 }
 71 void display()
 72 {
 73     student stu[20];
 74     FILE *fp;
 75     if ((fp = fopen("學生基本信息.txt", "r")) == NULL)
 76     {
 77         printf("打開文件失敗!");
 78     }
 79     printf("輸入學生的學號  姓名  性別  年齡  電話  籍貫  入學成績:\n");
 80     int i, n = 0;
 81     for (i = 0; fread(&stu[i], sizeof(student), 1, fp); i++)
 82     {
 83         n++;
 84     }
 85     for (i = 0; i<n; i++)
 86     {
 87         printf("%s  %s  %s  %d  %s  %s  %f\n", stu[i].xh, stu[i].xm, stu[i].xb, stu[i].nl, stu[i].dh, stu[i].jg, stu[i].rxcj);
 88     }
 89     fclose(fp);
 90 }
 91 void main(void)
 92 {
 93     int num;
 94     system("color F9");
 95     system("cls");
 96     system("mode con cols=100 lines=30");  //調整系統Console控制台顯示的寬度和高度,高度為30個字元,寬度為100個字元
 97     system("title 學生信息管理系統");       //起標題
 98     fflush(stdin);                           //清空輸入緩衝區
 99     do
100     {
101         num = menu();
102         switch (num)
103         {
104         case 1:add(); system("pause"); break;
105         case 2:display(); system("pause"); break;
106         case 3:search(); system("pause"); break;
107         case 4:sort(); system("pause"); break;
108         case 5:dele(); system("pause"); break;
109         case 6:update(); system("pause"); break;
110         case 0:printf("退出\n"); exit(1); system("pause"); break;
111             exit(1); break;
112         }
113     } while (1);
114 }
115 void search()
116 {
117     system("cls");
118     FILE *fp;
119     char delxh[11];
120     student stu[45];
121     char ch[2]; int num1;
122     printf("\t學生信息查詢\n");
123     printf("\t------------------\n");
124     printf("\t1.按學號查詢\n");
125     printf("\t2.按姓名查詢\n");
126     printf("\t------------------\n");
127     printf("請輸入你的選擇:");
128     gets_s(ch);
129     num1 = atoi(ch);
130     if (num1 == 1)
131     {
132         if ((fp = fopen("學生基本信息.txt", "r")) == NULL)
133         {
134             printf("打開文件失敗!");
135         }
136         int i, n = 0;
137         for (i = 0; fread(&stu[i], sizeof(student), 1, fp); i++)
138         {
139             n++;
140         }
141         fclose(fp);
142         printf("請輸入要查詢的學號:");
143         gets_s(delxh);
144         for (i = 0; i<n; i++)
145         {
146             if (!strcmp(stu[i].xh, delxh))
147             {
148                 printf("你要查詢的學生為:\n");
149                 printf("%s %s %s %d %s %s %6.2f\n", stu[i].xh, stu[i].xm, stu[i].xb, stu[i].nl, stu[i].dh, stu[i].jg, stu[i].rxcj);
150                 break;
151             }
152         }
153     }
154     else if (num1 == 2)
155     {
156         if ((fp = fopen("學生基本信息.txt", "r")) == NULL)
157         {
158             printf("打開文件失敗!");
159         }
160         int i, n = 0;
161         for (i = 0; fread(&stu[i], sizeof(student), 1, fp); i++)
162         {
163             n++;
164         }
165         fclose(fp);
166         printf("請輸入要查詢的姓名:");
167         gets_s(delxh);
168         for (i = 0; i<n; i++)
169         {
170             if (!strcmp(stu[i].xm, delxh))
171             {
172                 printf("你要查詢的學生為:\n");
173                 printf("%s %s %s %d %s %s %6.2f\n", stu[i].xh, stu[i].xm, stu[i].xb, stu[i].nl, stu[i].dh, stu[i].jg, stu[i].rxcj);
174                 break;
175             }
176         }
177     }
178 }
179 void update()
180 {
181     system("cls");
182     FILE *fp;
183     int i, j, m = 0, snum;
184     student stu[45];
185     char ch[2]; int num1;
186     char updatexh[11];
187     printf("\t學生信息修改\n");
188     printf("\t------------------\n");
189     printf("\t1.按學號修改\n");
190     printf("\t2.按姓名修改\n");
191     printf("\t------------------\n");
192     printf("請輸入你的選擇:");
193     gets_s(ch);
194     num1 = atoi(ch);
195     if (num1 == 1)
196     {
197         if ((fp = fopen("學生基本信息.txt", "ab+")) == NULL)
198         {
199             printf("can not open\n");
200             return;
201         }
202         while (!feof(fp))    //檢測文件是否達到哦末尾,出錯或者文件指針到了文件末尾(EOF)則返回 TRUE,否則返回 FALSE。
203             if (fread(&stu[m], sizeof(student), 1, fp) == 1)
204                 m++;
205         if (m == 0)  
206         {
207             printf("no record!\n");
208             fclose(fp);
209             return;
210         }
211         printf("請輸入要修改的學號:\n");
212         gets_s(updatexh);
213         for (i = 0; i<m; i++)                        // strcmp(const char *s1,const char *s2)
214             if (!strcmp(stu[i].xh, updatexh))        // 當s1<s2時,返回為負數;當s1=s2時,返回值= 0;當s1>s2時,返回正數。
215             {
216                 printf("你要修改的學生為:\n");
217                 printf("%s %s %s %d %s %s %6.2f\n", stu[i].xh, stu[i].xm, stu[i].xb, stu[i].nl, stu[i].dh, stu[i].jg, stu[i].rxcj);
218                 break;
219             }
220 
221         if (i<m)
222         {
223             printf("請輸入學生的姓名:");
224             scanf("%s", &stu[i].xm);
225             printf("請輸入學生的性別:");
226             scanf("%s", &stu[i].xb);
227             printf("請輸入學生的年齡:");
228             scanf("%d", &stu[i].nl);
229             printf("請輸入學生的電話:");
230             scanf("%s", &stu[i].dh);
231             printf("請輸入學生的籍貫:");
232             scanf("%s", &stu[i].jg);
233             printf("請輸入學生的成績:");
234             scanf("%f", &stu[i].rxcj);
235         }
236         else
237         {
238             printf("can not find!");
239             getchar();
240             return;
241         }
242         if ((fp = fopen("學生基本信息.txt", "wb")) == NULL)
243         {
244             printf("can not open\n");
245             return;
246         }
247         for (j = 0; j<m; j++)//將新修改的信息寫入指定的磁碟文件中
248             if (fwrite(&stu[j], sizeof(student), 1, fp) != 1)    
249                                                 //如果成功,該函數返回一個 size_t 對象,表示元素的總數,
250                                                 //該對象是一個整型數據類型。如果該數字與 nmemb 參數不同,則會顯示一個錯誤
251             {
252                 printf("can not save!");
253                 _getch();    //一個不回顯函數,從控制台讀取一個字元,但不顯示在屏幕上
254             }
255         fclose(fp);
256         getchar();                    //接收回車符,防止直接跳出
257         //fflush(stdin);                //沒用
258         //char c = getchar();        //此處疑問,為什麼用fflush(stdin) 不行,還是會直接退出程式,而用getchar(); 則不會
259         //printf("---%c---", c);    //測試發現是一個回車
260         
261 
262     }
263     else if (num1 == 2)
264     {
265         if ((fp = fopen("學生基本信息.txt", "ab+")) == NULL)
266         {
267             printf("can not open\n");
268             return;
269         }
270         while (!feof(fp))
271             if (fread(&stu[m], sizeof(student), 1, fp) == 1)
272                 m++;
273         if (m == 0)
274         {
275             printf("no record!\n");
276             fclose(fp);
277             return;
278         }
279         printf("請輸入要修改的姓名:\n");
280         gets_s(updatexh);
281         for (i = 0; i<m; i++)
282             if (!strcmp(stu[i].xm, updatexh))
283             {
284                 printf("你要修改的學生為:\n");
285                 printf("%s %s %s %d %s %s %6.2f\n", stu[i].xh, stu[i].xm, stu[i].xb, stu[i].nl, stu[i].dh, stu[i].jg, stu[i].rxcj);
286                 break;
287             }
288 
289         if (i<m)
290         {
291             printf("請輸入學生的學號:");
292             scanf("%s", &stu[i].xh);
293             printf("請輸入學生的性別:");
294             scanf("%s", &stu[i].xb);
295             printf("請輸入學生的年齡:");
296             scanf("%d", &stu[i].nl);
297             printf("請輸入學生的電話:");
298             scanf("%s", &stu[i].dh);
299             printf("請輸入學生的籍貫:");
300             scanf("%s", &stu[i].jg);
301             printf("請輸入學生的成績:");
302             scanf("%f", &stu[i].rxcj);
303         }
304         else
305         {
306             printf("can not find!");
307             getchar();
308             return;
309         }
310         if ((fp = fopen("學生基本信息.txt", "wb")) == NULL)
311         {
312             printf("can not open\n");
313             return;
314         }
315         for (j = 0; j<m; j++)//將新修改的信息寫入指定的磁碟文件中
316             if (fwrite(&stu[j], sizeof(student), 1, fp) != 1)
317             {
318                 printf("can not save!");
319                 _getch();
320             }
321         fclose(fp);
322     }
323 
324 }
325 
326 void dele()
327 {
328     system("cls");
329     FILE *fp;
330     char delxh[11];
331     student stu[45];
332     char ch[2]; int num1;
333     printf("\t學生信息刪除\n");
334     printf("\t------------------\n");
335     printf("\t1.按學號刪除\n");
336     printf("\t2.按姓名刪除\n");
337     printf("\t------------------\n");
338     printf("請輸入你的選擇:");
339     gets_s(ch);
340     num1 = atoi(ch);
341     if (num1 == 1)
342     {
343         if ((fp = fopen("學生基本信息.txt", "r")) == NULL)
344         {
345             printf("打開文件失敗!");
346         }
347         int i, j, n = 0;
348         for (i = 0; fread(&stu[i], sizeof(student), 1, fp); i++)
349         {
350             n++;
351         }
352         fclose(fp);
353         printf("請輸入要刪除的學號:");
354         gets_s(delxh);
355         for (i = 0; i<n; i++)
356         {
357             if (!strcmp(stu[i].xh, delxh))
358             {
359                 printf("你要刪除的學生為:\n");
360                 printf("%s %s %s %d %s %s %6.2f\n", stu[i].xh, stu[i].xm, stu[i].xb, stu[i].nl, stu[i].dh, stu[i].jg, stu[i].rxcj);
361                 break;
362             }
363         }
364         if (i == n)
365         {
366             printf("你要刪除的學生沒有找到!\n");
367         }
368         else
369         {
370             char ch;
371             printf("你是否刪除(y/n)?\n");
372             ch = getchar();
373             getchar();
374             if (ch == 'y' || ch == 'Y')
375             {
376                 for (j = i; j<n; j++)
377                     stu[j] = stu[j + 1];
378                 n--;
379                 if ((fp = fopen("學生基本信息.txt", "w")) == NULL)
380                 {
381                     printf("打開文件失敗!");
382                 }
	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • break語句(跳出本層迴圈) break 語句可以跳出所在層的迴圈,這些迴圈可以是for、while、do-while。 continue語句(跳出本輪迴圈體的剩餘語句,進入到當前迴圈下的下一輪迴圈體) 結束當前迴圈體剩下的語句,直接進入下一輪迴圈體的執行。 1、break的例子:求100以內的素 ...
  • 慕課網-跳跳虎-圖解+仿寫 新手都能學懂的SpringBoot源碼課-366元——全方位深入解析最新版SpringBoot源碼 慕課網-跳跳虎-圖解+仿寫 新手都能學懂的SpringBoot源碼課-366元——全方位深入解析最新版SpringBoot源碼 2020年1月4號更新——聯繫老闆微信:it ...
  • 如何實現伺服器。。。socket介面是實際上是操作系統提供的系統調用。socket的使用並不局限於Python語言,你可以用C或者JAVA來寫出同樣的socket伺服器,而所有語言使用socket的方式都類似(Apache就是使用C實現的伺服器) Web框架就是提前寫好了伺服器。不能跨語言的使用框架 ...
  • 1. Spider Middleware Spider Middleware是介入到Scrapy的Spider處理機制的鉤子框架。 當Downloader生成Response之後,Response會被髮送給Spider,在發送給Spider之前,Response會首先經過Spider Middlew ...
  • 問題: 最近在部署項目的時候出現數據亂碼的情況,經過一番查看項目都是用的UTF-8編碼格式,數據也是,但是經過調用介面傳給對方就亂碼了。 由於是部署在Windows環境下,Windows預設編碼GBK,這就導致了jvm運行時編碼不一致的問題,修改也很容易。 解決辦法: Linux環境下如果使用的UT ...
  • 1.參數會作為一個 Python 表達式(從技術上說是一個條件列表)被解析並求值 2.去除字元串兩邊的引號 srting 也可以用 3.字元串轉字典 4.傳遞全局變數 5.傳遞本地變數 ...
  • 1.python中函數的工作原理 python的解釋器,也就是python.exe(c編寫)會用PyEval_EvalFramEx(c函數)運行foo()函數 首先會創建一個棧幀(stack Frame),在棧幀對象的上下文裡面去運行這個位元組碼。 可以嘗試著去列印foo的位元組碼: 關於位元組碼的解釋: ...
  • python中的多線程其實並不是真正的多線程,如果想要充分地使用多核CPU資源,在python中大部分情況需要使用多進程。python提供了非常好用的多進程包Multiprocessing,只需要定義一個函數,python會完成其它所有事情。藉助這個包,可以輕鬆完成從單進程到併發執行的轉換。mult ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...