




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
第C語言實現(xiàn)新生入學登記系統(tǒng)printf("\n\n\n\n\n");
printf("\t|---------------歡迎進入----------------|\n");
printf("\t|
新生入學登記系統(tǒng)
|\n");
printf("\t|
主菜單
|\n");
printf("\t|
1.錄入學生信息
|\n");
printf("\t|
2.瀏覽學生信息
|\n");
printf("\t|
3.查找學生信息
|\n");
printf("\t|
4.刪除學生信息
|\n");
printf("\t|
5.修改學生信息
|\n");
printf("\t|
6.新生入學排名
|\n");
printf("\t|
0.退出系統(tǒng)
|\n");
printf("\t|-----------------------------------------|\n");
printf("\n");
printf("\t\t請選擇(0-6):");
}
(4)BeginingAndEnding.h
#ifndefBEGININGANDENDING_H_INCLUDED
#defineBEGININGANDENDING_H_INCLUDED
//關于啟動函數(shù)和結束函數(shù)
voidBegining();
voidEnding();
#endif//BEGININGANDENDING_H_INCLUDED
(5)BeginingAndEnding.c
#includestdio.h
#includeconio.h
//getc函數(shù)使用的頭文件
#include"system.h"
#include"AboutFiles.h"
#include"BeginingAndEnding.h"
#include"MyList.h"
voidBegining()
readInfoFromFile("studentList.txt");
voidEnding()
writeInfoToFile("studentList.txt");
}
(6)MyList.h
#ifndefMYLIST_H_INCLUDED
#defineMYLIST_H_INCLUDED
//關于鏈表的函數(shù)聲明
//創(chuàng)建節(jié)點
structNode*createNode(structstudentdata);
//插入節(jié)點
voidinsertNodeByHead(structstudentdata);
//指定位置刪除節(jié)點
voiddeleteAppointNode(char*studentId);
//查找功能
structNode*searchInfoByData(char*studentId);
//打印鏈表
voidprintList();
#endif//MYLIST_H_INCLUDED
(7)MyList.c
#includestdio.h
#includeconio.h
//getc函數(shù)使用的頭文件
#includewindows.h//Sleep函數(shù)使用的頭文件
#includestring.h//strcmp函數(shù)使用的頭文
#include"system.h"
#include"MyList.h"
structNode*studentList=NULL;
//鏈表的頭指針
//創(chuàng)建節(jié)點
structNode*createNode(structstudentstudentData)
structNode*newNode=(structNode*)malloc(sizeof(structNode));
if(newNode!=NULL)
{
newNode-studentData=studentData;
newNode-next=NULL;
}
returnnewNode;
//插入節(jié)點
voidinsertNodeByHead(structstudentdata)
structNode*newNode=createNode(data);
//表頭法插入,每次插入都將數(shù)據(jù)插入到頭節(jié)點的下一個,先判斷頭節(jié)點是否為空,為空則新節(jié)點就是頭節(jié)點,不為空,則插入在頭節(jié)點的下一個位置
if(studentList==NULL)
{
studentList=newNode;
}
else//不改變頭節(jié)點
{
newNode-next=studentList-next;
studentList-next=newNode;
}
//指定位置刪除節(jié)點(知道這個節(jié)點的前驅和后續(xù),然后進行刪除)
voiddeleteAppointNode(char*studentId)
//將鏈表頭部設為指定位置,先判斷頭節(jié)點是否為空,為空則鏈表沒有數(shù)據(jù),無法刪除
//如果頭節(jié)點不為空,則設頭結點為指定位置,如果頭結點是所找的節(jié)點,則刪除,如果不是,設頭結點的下一個為指定節(jié)點,頭結點為指定節(jié)點的前驅節(jié)點,一直向下查詢
//指定位置
structNode*posNode=studentList;
//指定位置的前面
structNode*posFrontNode=NULL;
//查找指定節(jié)點
if(posNode==NULL)
{
printf("數(shù)據(jù)為空無法刪除!\n");
return;
}
else
{
//姓名是字符串,不能直接比較,strcmp(),相等返回值為0,相同返回值為負數(shù)或者正數(shù)
if(strcmp(posNode-studentData.studentId,studentId)==0)
{
studentList=studentList-next;
free(posNode);
return;
}
else
{
posFrontNode=posNode;
posNode=posNode-next;
//posFrontNode=posNode;//!!
while(strcmp(posNode-studentData.studentId,studentId))
{
//繼續(xù)向下一個節(jié)點移動
posFrontNode=posNode;
posNode=posFrontNode-next;
if(posNode==NULL)//找到了鏈表尾部,沒有找到數(shù)據(jù)
{
printf("未找到指定位置,無法刪除!");
return;
}
}
//查到到對應數(shù)據(jù)后,進行刪除,將該節(jié)點架空,然后釋放該節(jié)點的存儲單元
posFrontNode-next=posNode-next;
free(posNode);
return;
}
}
//查找功能
structNode*searchInfoByData(char*studentId)
structNode*pMove;
pMove=studentList;
if(pMove==NULL)//頭節(jié)點為空,鏈表為空
{
//printf("學生鏈表為空!\n");
returnpMove;
}
else
{
//查找到或者查找到鏈表最后,則結束循環(huán),返回查詢結果,結果為空,有兩種可能,一種是鏈表中沒有數(shù)據(jù),另一種是沒有查詢到
while(pMove!=NULL)
{
if(strcmp(pMove-studentData.studentId,studentId)==0)//找見
{
//printf("已查找到!\n");
returnpMove;
}
else
{
pMove=pMove-next;
}
}
//printf("未找到!\n");
returnpMove;
}
//打印鏈表
voidprintList()
structNode*pMove=studentList;
//涉及到展示數(shù)據(jù)
//表頭
if(pMove==NULL)
{
printf("Nostudentrecord!Pleaseadd.\n");
return;
}
else
{
printf("\t-------------------------------------------------------------------------------------\n");
printf("\t|%-10s|%-7s|%-4s|%-4s|%-12s|%-12s|%-12s|%-5s|\n","學號","姓名","性別","年齡","班級","專業(yè)","電話","入學成績");
printf("\t-------------------------------------------------------------------------------------\n");
while(pMove)
printf("\t|%-10s|%-7s|%-4s|%-4d|%-12s|%-12s|%-12s|%-8d|\n",STUDENT_DATA);
printf("\t-------------------------------------------------------------------------------------\n");
pMove=pMove-next;
}
}
printf("\n");
}
(8)AddStudent.h
#ifndefADDSTUDENT_H_INCLUDED
#defineADDSTUDENT_H_INCLUDED
voidAddStudent();
//錄入學生信息
#endif//ADDSTUDENT_H_INCLUDED
(9)AddStudent.c
#includestdio.h
#includeconio.h
//getc函數(shù)使用的頭文件
#includewindows.h//Sleep函數(shù)使用的頭文件
#includestring.h//strcmp函數(shù)使用的頭文
#include"AddStudent.h"
#include"system.h"
#include
"MyList.h"
//錄入學生信息
voidAddStudent()
structstudentstudentData;
structNode*isNull=NULL;
//接收查詢的返回值
intiFlagExist;
//保證不重復輸入
charcFlag;
intret;
//用來接收scanf的返回值,判斷輸入數(shù)據(jù)是否正確
system("cls");
printf("=================================================================\n");
printf("\t請輸入需要刪除的學生的學號:");
gets(studentData.studentId);
pMove=searchInfoByData(studentData.studentId);
if(pMove)
//該學生存在,進行刪除
{
//先對學生信息進行展示
printf("\t-------------------------------------------------------------------------------------\n");
printf("\t|%-10s|%-7s|%-4s|%-4s|%-12s|%-12s|%-12s|%-5s|\n","學號","姓名","性別","年齡","班級","專業(yè)","電話","入學成績");
printf("\t-------------------------------------------------------------------------------------\n");
printf("\t|%-10s|%-7s|%-4s|%-4d|%-12s|%-12s|%-12s|%-8d|\n",STUDENT_DATA);
printf("\t-------------------------------------------------------------------------------------\n");
printf("\t已查找到該學生信息,是否刪除?(y/n)");
cFlag=getchar();
getchar();//吃掉緩沖區(qū)的空格
while(cFlag!='n'cFlag!='y')
{
printf("輸入有誤,請輸入‘y'或者‘n'!");
printf("\n請選擇是否輸入學生信息(y/n):");
cFlag=getchar();
getchar();
}
if(cFlag=='n')
return;
elseif(cFlag=='y')
{
deleteAppointNode(studentData.studentId);
printf("\t已刪除該學生信息!\n");
printf("\t刪除操作執(zhí)行結束!\n");
}
}
else//找到了鏈表的末尾,或者鏈表為空
{
printf("\t該學生不存在!無法執(zhí)行刪除操作\n");
}
}
(16)ModifyStudent.h
#ifndefMODIFYSTUDENT_H_INCLUDED
#defineMODIFYSTUDENT_H_INCLUDED
#include"system.h"
voidModifyStudent();//修改學生信息
voidShowModifyMenu();//展示修改選項菜單
voiddealSelection(structstudentstudentData,intselection,structNode*pMove);//處理用戶選擇的修改項
#endif//MODIFYSTUDENT_H_INCLUDED
(17)ModifyStudent.c
#includestdio.h
#includeconio.h
//getc函數(shù)使用的頭文件
#includewindows.h//Sleep函數(shù)使用的頭文件
#includestring.h//strcmp函數(shù)使用的頭文
#include"ModifyStudent.h"
#include"system.h"
#include"MyList.h"
//修改學生信息
voidModifyStudent()
structstudentstudentData;
structNode*pMove=NULL;//對學生信息查詢結果進行保存
intselection;
//保存選擇信息
charisContinue='n';
//是否繼續(xù)進行修改
system("cls");
printf("\n");
printf("\t================================================================\n");
if(studentList==NULL)
{
printf("學生登記為空,無法進行成績排名\n");
return;
}
else//學生鏈表頭指針不為空,代表學生鏈表中存有學生信息
{
pMove=studentList;
//pMove指向鏈表的頭
//通過遍歷得到鏈表有多少個存儲單元
for(i=0;pMove!=NULL;i++)
{
pMove=pMove-next;
}
length=i;
printf("現(xiàn)有學生總人數(shù)為%d\n",length);
//動態(tài)數(shù)組
stuRanking=(structstudentRanking*)malloc(length*sizeof(structstudentRanking));
if(stuRanking==NULL)
return;
//將需要輸出的學生信息復制到結構體數(shù)組當中
pMove=studentList;
for(j=0;jlength;j++)
{
strcpy(stuRanking[j].studentId,pMove-studentData.studentId);
strcpy(stuRanking[j].name,pMove-studentD);
strcpy(stuRanking[j].className,pMove-studentData.className);
stuRanking[j].score=pMove-studentData.score;
pMove=pMove-next;
}
//復制完成后,根據(jù)成績對學生進行排序
sortByScore(stuRanking,length);
//根據(jù)排序結果,為每名同學添加排名信息
Ranking(stuRanking,length);
//展示排名
printf("排名結果如下:\n");
printf("\t-------------------------------------------------------\n");
printf("\t|%-10s|%-7s|%-12s|%-5s|%-5s|\n","學號","姓名","班級","入學成績","全級排名");
printf("\t-------------------------------------------------------\n");
for(j=0;jlength;j++)
{
printf("\t|%-10s|%-7s|%-12s|%-8d|%-8d|\n",STUDENT_RANKING);
printf("\t-------------------------------------------------------\n");
}
}
printf("輸出排名信息完畢!\n");
system("pause");
//通過成績對鏈表中的數(shù)據(jù)進行排序
voidsortByScore(structstudentRanking*stuRanking,intlength)
//進行冒泡排序,從大到小排序
inti,j;
structstudentRankingtemp;
for(i=0;ilength-1;i++)
{
for(j=0;j(length-i-1);j++)
{
if(stuRanking[j].scorestuRanking[j+1].score)//后一項比前一項大,則交換兩個存儲單元中的數(shù)據(jù),一輪排序下來,最小項就位,在列表的最末尾
{
temp=*(stuRanking+j);
*(stuRanking+j)=*(stuRanking+j+1);
*(stuRanking+j+1)=temp;
}
}
}
voidRanking(structstudentRanking*stuRanking,intlength)
inti;
for(i=1;i=l
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 裝修材料清單合同協(xié)議
- 解除勞動合同和買斷協(xié)議
- 青少年實踐試題及答案解析
- 死亡角度測試題及答案
- 紡織品檢測員的心態(tài)與挑戰(zhàn)試題及答案
- 中醫(yī)藥現(xiàn)代化進程中愛爾蘭市場拓展策略與案例分析報告
- 2025年金融科技在跨境貿(mào)易融資中的應用與模式創(chuàng)新
- 2024廣告設計師考試模擬練習題試題及答案
- 紡織品設計師考試測驗試題及解析
- 漢字構造試題答案及解析
- 智能監(jiān)管系統(tǒng)構建-深度研究
- 鋼材交易中心項目可行性分析報告
- 檔案工作安全系列文件解讀
- 2024年內(nèi)蒙古呼和浩特中考歷史真題卷及答案解析
- 【MOOC答案】《中國文化傳承與科技創(chuàng)新》(北京郵電大學)中國慕課章節(jié)作業(yè)網(wǎng)課答案
- GB/T 45015-2024鈦石膏綜合利用技術規(guī)范
- 郵政社招筆試題庫
- 2023-2024學年北京市海淀區(qū)高二(上)期末語文試卷
- 《真希望你也喜歡自己》房琪-讀書分享
- 2025年教師資格考試高中物理面試試題與參考答案
- 粵人版(2024新版)七年級上冊地理期末復習考點背誦提綱
評論
0/150
提交評論