用c++模擬實現一個學生成績管理系統

https://blog.csdn.net/yanxiaolx/article/details/53393437

題目:用c++模擬實現一個學生成績的信息管理系統,要求能添加、刪除、修改、查看和保存學生的信息等功能

源代碼如下:

[cpp]?view plaincopy
  1. #define??_CRT_SECURE_NO_WARNINGS??
  2. ??
  3. #include<iostream>??
  4. using?namespace?std;??
  5. #include<string.h>??
  6. #include<fstream>??
  7. ??
  8. class?student??
  9. {??
  10. private:??
  11. ????student*?next;??
  12. public:??
  13. ????char?stu_num[15];??????????????????//學號??
  14. ????char?stu_name[30];????????????????//姓名??
  15. ????float?stu_score;??????????????????????//成績??
  16. ??
  17. ????void?afterInsert(student?*p);//在該節點后插入一個節點??
  18. ????void?afterDelete();//在該節點后刪除一個節點??
  19. ??????
  20. ????student?*getNext()//獲得下一個節點的指針??
  21. ????{???
  22. ????????return?next;???
  23. ????}??
  24. ??
  25. ????/***********查詢學生信息************/??
  26. ????void?getMage();??
  27. ??
  28. ????/******學生信息修改******/??
  29. ????void?changeMage(int?n,?char?*ptr);??
  30. ????void?changegrade(float?p);??
  31. ??
  32. ????/******構造*****/??
  33. ????student(char?*num,?char?*name,?float?score);??
  34. ????student();??
  35. };??
  36. ??
  37. void?student::changegrade(float?p)??
  38. {??
  39. ????stu_score?=?p;??
  40. }??
  41. ??
  42. student::student()???????????//構造??
  43. {??
  44. ????strcpy(stu_num,?"\0");??
  45. ????strcpy(stu_name,?"\0");??
  46. ????stu_score?=?0;??
  47. ????next?=?'\0';??
  48. }??
  49. ??
  50. student::student(char?*num,?char?*name,?float?score)??
  51. {??
  52. ????strcpy(stu_num,?num);??
  53. ????strcpy(stu_name,?name);??
  54. ????stu_score?=?score;??
  55. ????next?=?'\0';??
  56. }??
  57. ??
  58. void?student::afterInsert(student?*p)//插入節點??
  59. {??
  60. ????p->next?=?next;??
  61. ????next?=?p;??
  62. }??
  63. ??
  64. void?student::afterDelete()????????//刪除節點??
  65. {??
  66. ????student?*p?=?next;??
  67. ????next?=?p->next;??
  68. ????delete?p;??
  69. }??
  70. ??
  71. void?student::getMage()?????????????//獲得信息??
  72. {??
  73. ????cout?<<?"學號:"?<<?stu_num?<<?"??????姓名:"?<<?stu_name;??
  74. ????cout?<<?"??????c++成績:"?<<?stu_score?<<?endl;??
  75. }??
  76. ??
  77. void?student::changeMage(int?n,?char?*ptr)??
  78. {??
  79. ????switch?(n)??
  80. ????{??
  81. ????case?1:?strcpy(stu_num,?ptr);???
  82. ????????break;??
  83. ????case?2:?strcpy(stu_name,?ptr);??
  84. ????}??
  85. }??
  86. ??
  87. //建立鏈表函數??
  88. void??construct_list(student?*tail)??
  89. {??
  90. ????student?*p?=?new?student;??
  91. ????char?very[20];??
  92. ????float?achieve;??
  93. ????cout?<<?"請輸入學號:"?<<?endl;??
  94. ????cin?>>?very;??
  95. ????p->changeMage(1,?very);??
  96. ????cout?<<?"請輸入姓名:"?<<?endl;??
  97. ????cin?>>?very;??
  98. ????p->changeMage(2,?very);??
  99. ????cout?<<?"請輸入c++成績:"?<<?endl;??
  100. ????cin?>>?achieve;??
  101. ????p->changegrade(achieve);??
  102. ????system("cls");??
  103. ????cout?<<?"信息輸入完畢"?<<?endl;??
  104. ??
  105. ????for?(;?tail->getNext()?!=?'\0';)??
  106. ????{??
  107. ????????tail?=?tail->getNext();??
  108. ????}??
  109. ??
  110. ????tail->afterInsert(p);??
  111. }??
  112. ??
  113. /*********查詢信息*********/??
  114. student?*findmege(student?*head)??
  115. {??
  116. loop:??
  117. ????cout?<<?"1--按姓名查詢???????????2--按學號查詢??????????????q--返回上一級菜單"?<<?endl;??
  118. ????char?p[5],?ptr[20];??
  119. ????student?*mid?=?head;??
  120. ????cin?>>?p;??
  121. ??
  122. ????if?(p[0]?!=?'1'&&p[0]?!=?'2'&&p[0]?!=?'q'?||?strlen(p)>1)??
  123. ????{??
  124. ????????system("cls");??
  125. ????????cout?<<?"對不起,你的輸入有誤,請重新輸入!"?<<?endl;??
  126. ????????goto?loop;??
  127. ????}??
  128. ??
  129. ????switch?(p[0])??
  130. ????{??
  131. ????case?'1':??
  132. ????{??
  133. ????????system("cls");??
  134. ????????cout?<<?"請輸入要查找的姓名:"?<<?endl;??
  135. ????????cin?>>?ptr;??
  136. ??
  137. ????????for?(;?strcmp(ptr,?mid->stu_name)?!=?0;?mid?=?mid->getNext())??
  138. ????????{??
  139. ????????????if?(mid->getNext()?==?'\0')??
  140. ????????????{??
  141. ????????????????cout?<<?"對不起,你要查找的人不存在,請確認你的輸入是否正確!"?<<?endl;??
  142. ????????????????goto?loop;??
  143. ????????????}??
  144. ????????}??
  145. ????????return?mid;??
  146. ????}??
  147. ????case?'2':??
  148. ????{??
  149. ????????system("cls");??
  150. ????????cout?<<?"請輸入您要查找的學號:"?<<?endl;??
  151. ????????cin?>>?ptr;??
  152. ????????for?(;?strcmp(ptr,?mid->stu_num)?!=?0;?mid?=?mid->getNext())??
  153. ????????{??
  154. ????????????if?(mid->getNext()?==?'\0')??
  155. ????????????{??
  156. ????????????????cout?<<?"對不起,您要查找的內容不存在,請確認您的輸入是否正確!"?<<?endl;??
  157. ????????????????goto?loop;??
  158. ????????????}??
  159. ????????}??
  160. ????????return?mid;??
  161. ????}??
  162. ????case?'q':???
  163. ????{??
  164. ????????return?'\0';??
  165. ????}??
  166. ????default:??
  167. ????{??
  168. ????????system("cls");??
  169. ????????cout?<<?"對不起,您的輸入有誤,請重新輸入!"?<<?endl;??
  170. ????????goto?loop;??
  171. ????}??
  172. ????}??
  173. }??
  174. ??
  175. /******************刪除鏈表?節點***********************/??
  176. void?delete_list(student?*head)??
  177. {??
  178. ????student?*p?=?'\0';??
  179. ????char?selet[4];??
  180. ????system("cls");??
  181. ????cout?<<?"在刪除前,系統會根據您的提示找到您要刪除的學生信息!"?<<?endl;??
  182. ????p?=?findmege(head);??
  183. ????if?(p?!=?'\0')??
  184. ????{??
  185. ????????cout?<<?"確認要刪除嗎(yes/任意鍵返回)"?<<?endl;??
  186. ????????cin?>>?selet;??
  187. ??
  188. ????????if?(strcmp(selet,?"yes")?==?0)??
  189. ????????{??
  190. ????????????for?(;?head->getNext()?!=?p;?head?=?head->getNext());??
  191. ????????????head->afterDelete();??
  192. ????????????system("cls");??
  193. ????????????cout?<<?"該信息刪除成功!"?<<?endl;??
  194. ????????}??
  195. ????}??
  196. }??
  197. ??
  198. /*******************修改節點信息********************/??
  199. void?change_info(student?*head)??
  200. {??
  201. ????system("cls");??
  202. ????cout?<<?"在您修改前,系統會根據您提供的信息找的您要修改的信息:"?<<?endl;??
  203. ????student?*p?=?'\0';??
  204. ??
  205. ????float?achieve;??
  206. ????p?=?findmege(head);??
  207. ????if?(p?!=?'\0')??
  208. ????{??
  209. ????????cout?<<?"請輸入c++成績:"?<<?endl;??
  210. ????????cin?>>?achieve;??
  211. ????????p->changegrade(achieve);??
  212. ????????system("cls");??
  213. ????????cout?<<?"修改成功!"?<<?endl;??
  214. ????}??
  215. ??
  216. }??
  217. ??
  218. /**************輸出學生成績信息**************/??
  219. void?output(student?*head)??
  220. {??
  221. ????system("cls");??
  222. ????cout?<<?"1-查看指定學生信息;2-查看所有學生信息;3-分段輸出學生信息"?<<?endl;??
  223. ????char?ch;??
  224. ????int?n?=?0;??
  225. ????head?=?head->getNext();??
  226. ????cin?>>?ch;??
  227. ????switch?(ch)??
  228. ????{??
  229. ????case?'1':???
  230. ????????head?=?findmege(head);??
  231. ????????if?(head?==?'\0')??
  232. ????????{??
  233. ????????????break;??
  234. ????????}??
  235. ????????head->getMage();??
  236. ????????break;??
  237. ????case?'2':???
  238. ????while?(head)??
  239. ????{??
  240. ????????head->getMage();??
  241. ????????head?=?head->getNext();??
  242. ????}??
  243. ????break;??
  244. ????case?'3':???
  245. ????????cout?<<?"a-60分以下;b-60~70分之間;c-70~80分之間;d-80~90分之間;e-90~100分之間:"?<<?endl;??
  246. ????????cin?>>?ch;??
  247. ????????switch?(ch)??
  248. ????????{??
  249. ????????case?'a':??
  250. ????????while?(head)??
  251. ????????{??
  252. ????????????if?(head->stu_score?<=?60)??
  253. ????????????{??
  254. ????????????????head->getMage();??
  255. ????????????????n++;??
  256. ????????????}??
  257. ????????????head?=?head->getNext();??
  258. ????????}??
  259. ?????????break;??
  260. ????????case?'b':???
  261. ????????while?(head)??
  262. ????????{??
  263. ????????????if?(head->stu_score>60?&&?head->stu_score?<=?70)???
  264. ????????????{???
  265. ????????????????head->getMage();??
  266. ????????????????n++;???
  267. ????????????}??
  268. ????????????head?=?head->getNext();??
  269. ????????}??
  270. ????????break;??
  271. ????????case?'c':???
  272. ????????while?(head)??
  273. ????????{??
  274. ????????????if?(head->stu_score>70?&&?head->stu_score?<=?80)??
  275. ????????????{???
  276. ????????????????head->getMage();???
  277. ????????????????n++;???
  278. ????????????}??
  279. ????????????head?=?head->getNext();??
  280. ????????}??
  281. ????????break;??
  282. ????????case?'d':???
  283. ????????while?(head)??
  284. ????????{??
  285. ????????????if?(head->stu_score>80?&&?head->stu_score?<=?90)??
  286. ????????????{??
  287. ????????????????head->getMage();??
  288. ????????????????n++;??
  289. ????????????}??
  290. ????????????head?=?head->getNext();??
  291. ????????}??
  292. ????????break;??
  293. ????????case?'e':???
  294. ????????while?(head)??
  295. ????????{??
  296. ????????????if?(head->stu_score>90?&&?head->stu_score?<=?100)??
  297. ????????????{???
  298. ????????????????head->getMage();??
  299. ????????????????n++;??
  300. ????????????}??
  301. ????????????head?=?head->getNext();??
  302. ????????}??
  303. ????????}??
  304. ????????if?(n?==?0)??
  305. ????????{??
  306. ????????????cout?<<?"該分段內沒有您要找的學生信息"?<<?endl;??
  307. ????????}??
  308. ????}??
  309. }??
  310. ??
  311. /*****************主菜單************************/??
  312. void?mainmenu(student?*head)??
  313. {??
  314. ????char?selet[10];??
  315. ????int?n?=?1;??
  316. ????ofstream?outfile;??
  317. ????ifstream?infile;??
  318. ????student?*p,?*ptr;??
  319. ????student?*test?=?head,?*mid;??
  320. ????cout?<<?"*************************歡迎進入學生信息管理系統*************************"?<<?endl;??
  321. ????do?{??
  322. ????????cout?<<?"**************************************************************************"?<<?endl;??
  323. ????????cout?<<?"1.插入信息;???2.刪除信息;??3.修改信息;?4.查看信息;?5.保存??"?<<?endl;??
  324. ????????cout?<<?"按'q'鍵退出??????"?<<?endl;??
  325. ????????cout?<<?"**************************************************************************"?<<?endl;??
  326. ????????cin?>>?selet;??
  327. ????????if?(((selet[0]<'1'?||?selet[0]>'6')?&&?selet[0]?!=?'q')?||?strlen(selet)>1)??
  328. ????????{??
  329. ????????????system("cls");??
  330. ????????????cout?<<?"您的輸入有誤,請重新輸入!"?<<?endl;??
  331. ????????????break;??
  332. ????????}??
  333. ????????switch?(selet[0])??
  334. ????????{??
  335. ??
  336. ????????case?'1':??
  337. ????????????construct_list(head);??
  338. ????????????break;???
  339. ????????case?'2':???
  340. ????????????delete_list(head);???
  341. ????????????break;??
  342. ????????case?'3':???
  343. ????????????change_info(head);??
  344. ????????????break;??
  345. ????????case?'4':???
  346. ????????????output(head);??
  347. ????????????break;??
  348. ????????case?'5':????
  349. ????????????outfile.open("students.txt",?ios::out?|?ios::app);??
  350. ????????????for?(p?=?head->getNext();?p?!=?'\0';?p?=?p->getNext())??
  351. ????????????{??
  352. ????????????????outfile?<<?p->stu_name?<<?'?';??
  353. ????????????????outfile?<<?p->stu_num?<<?'?';??
  354. ????????????????outfile?<<?p->stu_score?<<?'?';??
  355. ????????????????outfile?<<?endl;??
  356. ????????????}??
  357. ????????????outfile.close();??
  358. ????????????system("cls");??
  359. ????????????cout?<<?"保存成功!"?<<?endl;??
  360. ????????????break;??
  361. ????????case?'q':???
  362. ????????????break;??
  363. ????????}??
  364. ????}?while?(selet[0]?!=?'q');??
  365. }??
  366. ??
  367. void?main()??
  368. {??
  369. ????student?head;??
  370. ????mainmenu(&head);??
  371. }??
運行結果部分截圖:



本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/383724.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/383724.shtml
英文地址,請注明出處:http://en.pswp.cn/news/383724.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux命令【四】文件+虛擬內存+常用系統函數

File*其實是一個結構體 文件描述符FD&#xff1a;索引到對應的磁盤文件文件讀寫位置指針FP_POS&#xff0c;如果同時讀寫需要注意文件指針的位置I/O緩沖區BUFFER&#xff1a;保存內存指針&#xff0c;默認大小是8kb&#xff0c;用于減小我們對硬盤操作的次數。因為我們對硬盤的…

Python3列表

操作&#xff1a;索引、切片、加、乘、檢查成員、確定序列長度、確定最大最小元素 定義&#xff1a; 列表名 [元素]下標列表名[x] 截取:列表名[x:y] 更新&#xff1a; list[x]y 或者使用append()方法添加列表項刪除&#xff1a; del list[x]常用操作&#xff1a; 截取與…

Linux驚群效應詳解(最詳細的了吧)

https://blog.csdn.net/lyztyycode/article/details/78648798?locationNum6&fps1 linux驚群效應詳細的介紹什么是驚群&#xff0c;驚群在線程和進程中的具體表現&#xff0c;驚群的系統消耗和驚群的處理方法。1、驚群效應是什么&#xff1f;驚群效應也有人叫做雷鳴群體效應…

epoll原理詳解(最清晰)

https://blog.csdn.net/lyztyycode/article/details/79491419我只是把內容搬運過來做個記錄&#xff0c;方便自己以后回頭看。第一部分&#xff1a;select和epoll的任務關鍵詞&#xff1a;應用程序 文件句柄 用戶態 內核態 監控者要比較epoll相比較select高效在什么地方&#x…

Linux命令【五】系統函數

系統文件函數 stat函數 指針如果沒有const一般表示傳出參數&#xff0c;如果加const表示傳入參數 struct stat dev_t st_dev文件設備編號ino_t st_ino節點 inode號是唯一的&#xff0c;每個inode節點的大小一般是128字節活著256字節&#xff0c;一般文件每2KB就設置一個ino…

生產者-消費者模型的兩種實現方式

https://www.cnblogs.com/caolicangzhu/p/7086176.html本文主要來總結生產者-消費者模型的代碼實現,至于其原理,請大家自行百度. 一、基于鏈表的生產-消費模型(條件變量)我們以鏈表為例,生產者進行頭部插入,消費者進行頭部刪除,因此,先將鏈表相關操作封裝為LinkList.h,具體代碼…

Linux系統【一】CPU+MMU+fork函數創建進程

切板中的內容輸出到文件### 進程相關概念 程序&#xff1a;編譯好的二進制文件&#xff0c;在磁盤上&#xff0c;不占用系統資源&#xff08;不包括磁盤&#xff09;。&#xff08;劇本&#xff09; 進程&#xff1a;占用系統資源&#xff0c;是程序的一次運行。&#xff08;戲…

Ubuntu卸載軟件

用過使用dpkg軟件管理工具得到所有已經安裝的軟件&#xff0c;如果不清楚軟件的全名可以使用grep命令進行查找 然后再使用sudo apt-get remove --purge 軟件名卸載軟件&#xff08;--purge參數會刪除配置文件&#xff0c;刪的干凈一些&#xff09; 例如&#xff1a;

一個重要且實用的signal---SIGCHLD

https://blog.csdn.net/lyztyycode/article/details/78150805SIGCHLD(修改)因為筆者之前的文章里面有錯誤&#xff0c;今天發現&#xff0c;立馬做個修改。在下面我的一段關于sigchld信號相對于直接調用wait函數的好處時&#xff0c;我說調用wait函數要一直檢測子進程是否執行完…

數據結構實驗之鏈表七:單鏈表中重復元素的刪除

https://blog.csdn.net/blessingxry/article/details/794455111.知識點&#xff1a;逆序建立鏈表&#xff0b;節點刪除 2.題意&#xff1a;按照數據輸入的相反順序&#xff08;逆位序&#xff09;建立一個單鏈表&#xff0c;并將單鏈表中重復的元素刪除&#xff08;值相同的元素…

Python3函數和代碼復用

函數的定義 def 函數名([參數列表]):注釋函數體注意事項 函數形參不需要聲明類型&#xff0c;可以使用return語句在結束函數執行的同時返回任意類型的值&#xff0c;函數返回值類型與return語句返回表達式i的類型一致 即使該函數不需要接受任何參數&#xff0c;也必須保留一堆…

一文說盡C++賦值運算符重載函數(operator=)

http://www.cnblogs.com/zpcdbky/p/5027481.html在前面&#xff1a;關于C的賦值運算符重載函數(operator)&#xff0c;網絡以及各種教材上都有很多介紹&#xff0c;但可惜的是&#xff0c;內容大多雷同且不全面。面對這一局面&#xff0c;在下在整合各種資源及融入個人理解的基…

Python a和a[:]的區別

簡單來講a[:]是深復制&#xff0c;a是淺復制&#xff0c;相當于賦值a的話是賦值了指針&#xff0c;賦值a[:]相當于復制了a對應的那段空間 例如&#xff1a; a [1,1,1,1,1,1]for x in a:if x1:a.remove(x)print(a)運行結果&#xff1a; remove操作是移除序列中第一個x元素。…

約瑟夫環(c語言程序完整版)

https://blog.csdn.net/m_hahahaha1994/article/details/51742453約瑟夫環&#xff08;約瑟夫問題&#xff09;是一個數學的應用問題&#xff1a;已知n個人&#xff08;以編號1&#xff0c;2&#xff0c;3…n分別表示&#xff09;圍坐在一張圓桌周圍。從編號為k的人開始報數&am…

Linux系統【二】exec族函數及應用

文件描述符 文件描述符表是一個指針數組&#xff0c;文件描述符是一個整數。 文件描述符表對應的指針是一個結構體&#xff0c;名字為file_struct&#xff0c;里面保存的是已經打開文件的信息 需要注意的是父子進程之間讀時共享&#xff0c;寫時復制的原則是針對物理地址而言…

白話C++系列(27) -- RTTI:運行時類型識別

http://www.cnblogs.com/kkdd-2013/p/5601783.htmlRTTI—運行時類型識別 RTTI&#xff1a;Run-Time Type Identification。 那么RTTI如何來體現呢&#xff1f;這就要涉及到typeid和dynamic_cast這兩個知識點了。為了更好的去理解&#xff0c;那么我們就通過一個例子來說明。這個…

使用頭文件的原因和規范

原因 通過頭文件來調用庫功能。在很多場合&#xff0c;源代碼不便&#xff08;或不準&#xff09;向用戶公布&#xff0c;只 要向用戶提供頭文件和二進制的庫即可。用戶只需要按照頭文件中的接口聲明來調用庫 功能&#xff0c;而不必關心接口怎么實現的。編譯器會從庫中提取相應…

轉圈踢人問題

https://www.cnblogs.com/lanxuezaipiao/p/3339603.html 有N個人圍一圈依次報數&#xff0c;數到3的倍數的人出列&#xff0c;問當只剩一個人時他原來的位子在哪里&#xff1f; 解答&#xff1a;經典的轉圈踢人問題&#xff0c;好吧專業一點&#xff0c;約瑟夫環問題&#xff0…

Linux系統【三】回收子進程

孤兒進程 父進程先于子進程結束&#xff0c;則子進程成為孤兒進程&#xff0c;子進程的父進程成為init進程&#xff0c;則稱init進程領養孤兒進程。現在好像是用戶進程中的system進程。 僵尸進程 進程終止&#xff0c;父進程不進行回收&#xff0c;自己成殘留資源(PCB)存放在…

string類的基本實現

https://blog.csdn.net/qq_29503203/article/details/52265829在面試中面試官常常會讓你寫出string類的基本操作&#xff0c;比如&#xff1a;構造函數&#xff0c;析構函數&#xff0c;拷貝構造等等.下面是除此之外的一些操作&#xff0c;希望可以幫助你更好的理解string以便以…