C語言編寫實現(xiàn)學生管理系統(tǒng)_第1頁
C語言編寫實現(xiàn)學生管理系統(tǒng)_第2頁
C語言編寫實現(xiàn)學生管理系統(tǒng)_第3頁
C語言編寫實現(xiàn)學生管理系統(tǒng)_第4頁
C語言編寫實現(xiàn)學生管理系統(tǒng)_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

第C語言編寫實現(xiàn)學生管理系統(tǒng)本文實例為大家分享了C語言實現(xiàn)學生管理系統(tǒng)的具體代碼,供大家參考,具體內容如下

學生信息管理系統(tǒng)是一個基于C語言開發(fā)的系統(tǒng),其中有用到冒泡排序、指針、結構體、二位數(shù)組等知識。通過模塊化的方法編寫各個函數(shù),其中在主界面函數(shù)調用各個模塊的函數(shù)的實現(xiàn)以下具體功能:

1、學生信息的增刪改查

2、學生成績的排序

3、統(tǒng)計學生人數(shù)

4、顯示所有學生的信息。

5、對學生信息存檔

本實驗通過在main函數(shù)打開保存數(shù)據(jù)結果的文檔和調用主界面函數(shù);在主界面函數(shù)welcom()中實現(xiàn)邊框的繪制,以及顯示各個功能及各個功能對應的函數(shù)實現(xiàn)方法。

錄入信息函數(shù)addInfo():此函數(shù)通過結構體student來保存錄入的信息,其中為了確保數(shù)據(jù)的后續(xù)操作的準確性,通過學號的唯一性來標識每個學生的信息,通過編寫及調用一個isIdSame()函數(shù),該函數(shù)通過遍歷所有學號確認學號來保障學號的唯一性,學號重復會提示用戶需要重新輸入函數(shù)。

查找學生信息函數(shù):通過學號查找學生的信息,編寫并調用一個findIndex()函數(shù),該函數(shù)會遍歷結構體的學號信息,查詢到會返回該學號的坐標,沒有找到該學號則返回-1;通過變量target來保存返回的結果。如果target不等于-1,則程序找到了該學號,通過編寫并調用一個showInfo()函數(shù)來輸出所有該學生的信息;否則輸出查詢此人,因為下標不可能為負數(shù)。

更新學生信息函數(shù)update():通過學號來找到該學生,調用findIndex()函數(shù)來確定該學生的位置,如果返回結果是小于0則函數(shù)結束,查無此人;若大于0則找到該學生,通過dowhile函數(shù)switch選擇語句的嵌套來進行用戶需要求改某一項的內容。

刪除函數(shù)del():查找學生的步驟跟更新學生信息函數(shù)的流程一樣,如果findIndex()函數(shù)小于0則函數(shù)結束,否則通過一個for循環(huán)把結構體的數(shù)組從光標開始往前覆蓋從而達到刪除效果。

插入學生信息函數(shù)inserInfo():通過要求用戶輸入位置來定位插入到位置,輸入用戶輸入的大于結構體數(shù)組的總數(shù)則插入到最后一個數(shù)組。否則通過一個for循環(huán),把數(shù)組從最后開始往后移一位,把用戶輸入的位置的結果移到后一數(shù)組就編寫并調用插入函數(shù)inserCurrentInfo()對當前位置數(shù)組進行覆蓋插入。inserCurrentInfo()函數(shù)只負責對接收到的該位置的元素所有信息的寫入。

排序函數(shù)sortTotal():創(chuàng)建一個臨時變量提供元素與元素之間交換信息。通過雙循環(huán)嵌套結構進行結構體的分數(shù)進行大小對比、交換位置來進行冒泡排序。最后排序完成之后輸出分數(shù)由高到低排序的所有學生的信息。

顯示學生信息函數(shù)showAllInfo():該函數(shù)通過全局變量count(該變量記錄了所有添加、插入或刪除過的學生信息,能準確記錄學生的總人數(shù))通過for循環(huán)去遍歷student結構體,從而輸出所有的所生信息。

學生數(shù)據(jù)存檔函數(shù)writeData():該函數(shù)定義一個指針,以寫入方式打開stu.txt文本,并把該文本的地址賦給指針fp。通過一個for循環(huán)遍歷結構體里的元素,把結構體里的元素的屬性輸入到stu.txt文本。

#includestdio.h

#includestdlib.h

#includestring.h

#includeconio.h

#includewindows.h

voidaddInfo();//添加

voidwelcom();//主界面

voidshowAllInfo();//展示所有信息

voidshowInfo(structStudentstudent);//展示學生信息

intfindIndex(structStudentstudent[],intid);//根據(jù)學號返回對應下標

voiddel();//刪除

voidsearch();//查找學生信息

voidupdata();//更新

voidsortTotal();//按總分排序

voidwriteData();//數(shù)據(jù)寫入文件中

voidinitData();//初始化數(shù)據(jù)從文件中讀取數(shù)據(jù),初始化數(shù)組

voidshowCount();//展示存儲學生個數(shù)

voidinserInfo();//插入學生信息

voidinserCurrentInfo(intsite);//當前位置插入

voidcon();//按任意鍵繼續(xù)

intfind1(structStudentstudent[],intid);//判斷學號是否有重復重復返回1不重復返回0

voidisIdSame(intx);//校驗所輸入學號是否重復

voidgotoxy(intx,inty);//光標定位

intcolor(intc);//設置顏色輸出

structStudent{

intid;

charname[20];

int_math;

int_chinese;

int_english;

inttotal;//總分

}student[500];

intcount=0;//記錄當前數(shù)組中存儲學生個數(shù)

//主函數(shù)

intmain(){

initData();

welcom();

return0;

//光標定位

voidgotoxy(intx,inty)

COORDpos;

pos.X=x;

//橫坐標

pos.Y=y;

//縱坐標

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

//設置顏色輸出

intcolor(intc)

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);

//更改文字顏色

return0;

//主界面

voidwelcom()

while(1){

system("cls");

intn;

inti,j=1;

color(10);

//淡綠色邊框

for(i=5;i=35;i++)

//循環(huán)y軸坐標,打印輸出上下邊框===

{

for(j=10;j=57;j++)

//循環(huán)x軸坐標,打印輸出左右邊框||

{

gotoxy(j,i);

if(i==5||i==35)printf("=");

//輸出上下邊框===

elseif(j==10||j==56)printf("||");

//輸出左右邊框||

}

}

color(15);//白色

gotoxy(25,8);

printf("學生信息管理系統(tǒng)");

color(14);

//設置字體顏色為黃色

gotoxy(15,12);

printf("1:錄入學生信息");

gotoxy(35,12);

printf("2.查找學生信息");

gotoxy(15,16);

printf("3.刪除學生信息");

gotoxy(35,16);

printf("4.修改學生信息");

gotoxy(15,20);

printf("5.插入學生信息");

gotoxy(35,20);

printf("6.按照學生成績排序");

gotoxy(15,24);

printf("7.統(tǒng)計學生總數(shù)");

gotoxy(35,24);

printf("8.顯示所有學生信息");

gotoxy(15,28);

printf("9.學生數(shù)據(jù)存檔并退出");

gotoxy(25,32);

intchoose;

printf("請選擇:[]\b\b");//\b光標回退一格

color(15);//

顏色變回白色

scanf("%d",choose);

switch(choose){

case1:addInfo();break;

case2:search();break;

case3:del();break;

case4:updata();break;

case5:inserInfo();break;

case6:sortTotal();break;

case7:showCount();break;

case8:showAllInfo();break;

case9:writeData();exit(0);

}

}

//添加

voidaddInfo(){

system("cls");

printf("\t添加學生信息\n");

printf("請輸入學號\n");

isIdSame(count);

printf("請輸入姓名\n");

scanf("%s",student[count].name);

printf("請輸入語文成績\n");

scanf("%d",student[count]._chinese);

printf("請輸入數(shù)學成績\n");

scanf("%d",student[count]._math);

printf("請輸入英語成績\n");

scanf("%d",student[count]._english);

student[count].total=student[count]._chinese+student[count]._english+student[count]._math;

printf("%s的信息錄入成功\n\n",student[count].name);

intchoose;

printf("1繼續(xù)2返回主界面\n");

count++;

scanf("%d",choose);

if(choose==1){

addInfo();

}

system("cls");

//查找展示結果

voidsearch(){

system("cls");

intid;

printf("請輸入你想查找學生的學號\n");

scanf("%d",id);

inttarget=findIndex(student,id);

//目標下表

intflag=1;//是否存在要查詢的學號

//for循環(huán)對比

if(target!=-1)

{

printf("\n\t查詢結果\n\n");

showInfo(student[target]);

con();

}

else{//輸出查詢結果

printf("\n查無此人\n");

con();

}

//更新

voidupdata(){

system("cls");

intid;

printf("請輸入你要修改學生的學號\n");

scanf("%d",id);

int

target=findIndex(student,id);

if(target0){

printf("查無此人");

con();

}else{

intflag=1;

do{

intchoose=0;

printf("請輸入需要修改的選項\t(1.學號\t2.姓名\t3.語文\t4.數(shù)學\t5.英語):\n");

scanf("%d",choose);

switch(choose){

case1:

printf("請輸入學號\n");

//

scanf("%d",student[target].id);

isIdSame(target);

break;

case2:

printf("請輸入姓名\n");

scanf("%s",student[target].name);

break;

case3:

printf("請輸入語文成績\n");

scanf("%d",student[target]._chinese);

break;

case4:

printf("請輸入數(shù)學成績\n");

scanf("%d",student[target]._math);

break;

case5:

printf("請輸入英語成績\n");

scanf("%d",student[target]._english);

break;

}

student[target].total=student[target]._chinese+student[target]._english+student[target]._math;

printf("%s的信息修改成功\n",student[target].name);

printf("\n按1繼續(xù)按2退出修改\n");

intchoose2;

scanf("%d",choose2);

if(choose2==1){

flag=1;

}else{

flag=0;

}

}while(flag);

}

voiddel(){

system("cls");

intid;

inttarget;//目標元素的下標

printf("\n請輸入你想刪除學生的學號\n");

scanf("%d",id);

target=findIndex(student,id);

if(target0){

printf("\n查無此人\n");

con();

}else{

for(inti=target;icount;i++){

student[i]=student[i+1];//刪除操作后一位元素覆蓋前一位元素

}

printf("刪除成功\n");

con();

count--;

}

//插入學生信息

voidinserInfo(){

system("cls");

intsite;//位置

printf("請輸入你要插入學生信息的位置(從0開始):\n");

scanf("%d",site);

//插入位置大于總數(shù),則插入在數(shù)組最后一位

if(sitecount){

inserCurrentInfo(count);

printf("%s的信息插入成功\n",student[count].name);

}else{

//不是最后一位從當前位置數(shù)組全部后移一位

for(inti=count;i=site;i--){

student[i+1]=student[i];

}

//在當前位置添加學員

inserCurrentInfo(site);

printf("%s同學的信息插入成功\n",student[site].name);

con();

}

//當前位置插入

voidinserCurrentInfo(intsite){

printf("請輸入學號\n");

isIdSame(site);

printf("請輸入姓名\n");

scanf("%s",student[site].name);

printf("請輸入語文成績\n");

scanf("%d",student[site]._chinese);

printf("請輸入數(shù)學成績\n");

scanf("%d",student[site]._math);

printf("請輸入英語成績\n");

scanf("%d",student[site]._english);

student[site].total=student[site]._chinese+student[site]._english+student[site]._math;

count++;

con();

//判斷學號是否重復重復返回1否則返回0

intfind1(structStudentstudent[],intid)

inttemp=0;

for(inti=0;icount;i++)

if(student[i].id==id)

{

temp=1;

break;

}

returntemp;

//校驗所添加學號是否重復

voidisIdSame(intx){

intinputId;

scanf("%d",inputId);

do{

if(find1(student,inputId)){

printf("學號有重復,請重新輸入\n");

scanf("%d",inputId);

}

else

{

student[x].id=inputId;

break;

}

}while(1);

//根據(jù)學號返回下標

intfindIndex(structStudentstudent[],intid){

inttemp;

for(inti=0;icount;i++){

if(student[i].id==id){

temp=i;

break;

}else{

temp=-1;

}

}

returntemp;

//按總分排序

voidsortTotal(){

//冒泡排序

structStudenttemp;//元素與元素交換的臨時容器

for(inti=0;icount-1;i++){

for(intj=0;jcount-1-i;j++){

if(student[j].totalstudent[j+1].total){

temp=student[j+1];

student[j+1]=student[j];

student[j]=temp;

}

}

}

printf("排序完成");

showAllInfo();

//按任意鍵繼續(xù)

voidcon(){

printf("\n按任意鍵繼續(xù)\n");

getch();

//展示學生總個數(shù)

voidshowCount(){

system("cls");

printf("\n\t學生總個數(shù)為:%d個\n",count);

con();

//初始化數(shù)據(jù)

voidinitData(){

FILE*fp=NULL;

fp=fopen(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論