C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)_第1頁
C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)_第2頁
C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)_第3頁
C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)_第4頁
C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)有朋友最近在做c語言課設(shè),要求寫一個(gè)班級(jí)成績(jī)管理系統(tǒng),便寫份簡(jiǎn)單的代碼來玩。代碼原創(chuàng),未參考任何其他人的代碼

本程序主要采用結(jié)構(gòu)體數(shù)組本文件采用多文件編寫,由于程序規(guī)模小,故未采用編寫頭文件的方式使用#pragmaonce來防止頭文件重復(fù)包含

怎么使用本程序看看注釋應(yīng)該就知道了。runmain.c就行。其他各文件作用:

def.c定義了一些常量和全局變量,結(jié)構(gòu)體myIO.c實(shí)現(xiàn)了成績(jī)錄入和成績(jī)打印輸出file.c實(shí)現(xiàn)了將成績(jī)保存為文件menu.c實(shí)現(xiàn)了菜單功能function.c包含其他一些要用的函數(shù)

main.c

#include"menu.c"

intmain()

select();

return0;

}

def.c

//相同頭文件只包含一次,后不贅述

#pragmaonce

#includestdio.h

#includestdlib.h

#includestring.h

#defineOK1

#defineERROR0

#defineTRUE1

#defineFALSE0

#defineStatusint

//課程

typedefstructCourse

charname[30];

intscore;

}Course,*pCourse;

//學(xué)生

typedefstructStudent

charnumber[30];

charname[30];

pCoursepC;

}Student,*pStudent;

//n是學(xué)生數(shù),m是課程數(shù)

intn,m;

charcourseName[30],studentName[30],course[20][30];

pStudentpS=NULL;

myIO.c

#pragmaonce

#include"def.c"

pStudentinputStudentInfo(void);

voidprintStudentInfo(pStudentpS);

//錄入學(xué)生信息

pStudentinputStudentInfo(void)

inti,j;

printf("Pleaseinputthenumberofstudentsandcourses:");

scanf("%d%d",n,

printf("Pleaseinputthenameofcourses:");

for(i=0;ii++)

{

scanf("%s",course[i]);

}

pStudentpS=(pStudent)malloc(sizeof(Student)*n);

if(!pS)

returnNULL;

printf("Pleaseinputtheinfo:\n");

for(i=0;ii++)

{

pS[i].pC=(pCourse)malloc(sizeof(Course)*m);

if(!pS[i].pC)

returnNULL;

scanf("%s%s",pS[i].name,pS[i].number);

for(j=0;jj++)

{

strcpy(pS[i].pC[j].name,course[j]);

scanf("%d",pS[i].pC[j].score);

}

}

returnpS;

//打印所有學(xué)生信息

voidprintStudentInfo(pStudentpS)

inti,j;

//打印標(biāo)題

printf("Name\tnumber\t");

for(i=0;im-1;i++)

printf("%s\t",course[i]);

printf("%s\n",course[i]);

//顯示信息

for(i=0;ii++)

{

printf("%s\t%s\t",pS[i].name,pS[i].number);

for(j=0;jm-1;j++)

printf("%d\t",pS[i].pC[j].score);

printf("%d\n",pS[i].pC[j].score);

}

}

file.c

#pragmaonce

#include"def.c"

StatussaveStudentInfo(pStudentpS);

StatussaveStudentInfo(pStudentpS)

FILE*fp;

inti,j;

charfilename[30],str[100]="studentnumber";

printf("pleaseinputthefilename:");

scanf("%s",filename);

fp=fopen(filename,"w");

if(!fp)

returnERROR;

for(i=0;ii++)

{

strcat(str,"");

strcat(str,course[i]);

}

strcat(str,"\n");

for(i=0;ii++)

{

strcat(str,pS[i].name);

strcat(str,"");

strcat(str,pS[i].number);

for(j=0;jj++)

{

charscore[30];

itoa(pS[i].pC[j].score,score,10);

strcat(str,"");

strcat(str,score);

}

strcat(str,"\n");

}

fputs(str,fp);

fclose(fp);

returnOK;

}

menu.c

#pragmaonce

#include"def.c"

#include"myIO.c"

#include"file.c"

#include"function.c"

voidmenu();

voidselect();

//菜單

voidmenu()

printf("------------------------------------\n");

printf("|

Menu

|\n");

printf("|

1.input

|\n");

printf("|

2.show

|\n");

printf("|

3.save

|\n");

printf("|

4.sort

|\n");

printf("|

5.modify

|\n");

printf("|

6.count

|\n");

printf("|

0.exit

|\n");

printf("------------------------------------\n");

voidselect()

intbranch;

while(TRUE)

{

system("cls");

menu();

printf("[Input]:");

scanf("%d",branch);

if(!branch)

break;

switch(branch)

{

case1:

{

pS=inputStudentInfo();

if(pS==NULL)

printf("inputerror!pleaseinputagain\n");

else

printf("Inputsuccess!\n");

system("pause");

break;

}

case2:

{

printStudentInfo(pS);

system("pause");

break;

}

case3:

{

if(OK==saveStudentInfo(pS))

printf("Savesuccess!\n");

else

printf("Savefail!\n");

system("pause");

break;

}

case4:

{

sort(pS);

printf("sortsuccess\n");

system("pause");

break;

}

case5:

{

intres=modify(pS);

if(res)

{

printf("changesuccess!\n");

}

else

{

printf("changefail!\n");

}

system("pause");

break;

}

case6:

{

intchoose;

//輸入1顯示每門課程最高成績(jī)信息

//輸入2顯示每門課程平均成績(jī)信息

printf("choose1forthehighestscore:\n");

printf("choose2fortheaveragescore:\n");

printf("[Input]:");

scanf("%d",choose);

if(choose==1)

{

showMax(pS);

}

elseif(choose==2)

{

showAverage(pS);

}

else

{

//輸入非法提示信息

printf("Inputerror!\n");

}

system("pause");

break;

}

}

}

}

function.c

#include"def.c"

voidsort(pStudentpS);

voidSwap(pStudents1,pStudents2);

voidshowAverage(pStudentpS);

voidshowMax(pStudentpS);

Statusmodify(pStudentpS);

//按課程成績(jī)排序

voidsort(pStudentpS)

intcourseNumber,i,j,k;

charcourseName[30];

printf("pleaseinputthecoursenamewhichyouwanttosort:");

scanf("%s",courseName);

for(courseNumber=0;courseNumbercourseNumber++)

if(strcmp(course[courseNumber],courseName)==0)

break;

//如果找不到課程,則認(rèn)為是按總分排序

if(courseNumber==m)

{

printf("Sortastotalscore:\n");

//選擇排序

for(i=0;in-1;i++)

{

intflag=i;

for(j=i+1;jj++)

{

inttotalScore_1=0,totalScore_2=0;

for(k=0;kk++)

{

totalScore_1+=pS[j].pC[k].score;

totalScore_2+=pS[flag].pC[k].score;

}

if(totalScore_1totalScore_2)

{

flag=j;

}

}

Swap(pS[i],pS[flag]);

}

}

else

{

//選擇排序

for(i=0;in-1;i++)

{

intflag=i;

for(j=i+1;jj++)

{

if(pS[j].pC[courseNumber].scorepS[flag].pC[courseNumber].score)

{

flag=j;

}

}

Swap(pS[i],pS[flag]);

}

}

//修改學(xué)生信息

Statusmodify(pStudentpS)

//密碼是1314

charpassword[30]="1314",psd[30];

charnumber[30];

intscore,i,j;

printf("pleaseinputpassword:");

scanf("%s",psd);

//密碼正確才繼續(xù),否則返回ERROR

if(strcmp(password,psd)==0)

{

printf("pleaseinputthestudent'snumber:");

scanf("%s",number);

for(i=0;ii++)

{

//找到學(xué)生則繼續(xù),否則返回ERROR

if(strcmp(pS[i].number,number)==0)

{

printf("pleaseinputthecourseandscoreonebyone:\n");

scanf("%s%d",courseName,score);

for(j=0;jj++)

{

//找到課程才繼續(xù),否則返回ERROR

if(strcmp(pS[i].pC[j].name,courseName)==0)

{

//修改課程成績(jī)

pS[i].pC[j].score=score;

returnOK;

}

}

returnERROR;

}

}

returnERROR;

}

else

returnERROR;

//輸出各課程最高分的學(xué)生

voidshowMax(pStudentpS)

inti,j,max;

for(i=0;ii++)

{

max=0;

for(j=0;jj++)

{

if(pS[j].pC[i].scorepS[m

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論