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頁,還剩19頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

第C++實現(xiàn)歌手比賽評分系統(tǒng)本文實例為大家分享了C++實現(xiàn)歌手比賽評分系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

(一)需求和規(guī)格說明

對一次歌手比賽的成績進行管理,功能要求:

1、輸入每個選手的數(shù)據(jù)包括編號、姓名、十個評委的成績,根據(jù)輸入計算

出總成績和平均成績(去掉最高分,去掉最低分)。

2、顯示主菜單如下:

1)輸入選手數(shù)據(jù)

2)評委打分

3)成績排序(按平均分)

4)數(shù)據(jù)查詢

5)追加選手數(shù)據(jù)

6)寫入數(shù)據(jù)文件

7)退出系統(tǒng)。

(二)設(shè)計

根據(jù)上述需求,運用鏈表存儲歌手的數(shù)據(jù),

1.數(shù)據(jù)的生成

歌手比賽選手首先我們需要歌手的基本信息,將每一位用戶的編號、姓名輸入系統(tǒng)中,然后進行評委打分,之后我們對數(shù)據(jù)進行處理分析,計算出總分和平均值,并以.txt文件的格式儲存起來。

2.數(shù)據(jù)的存儲結(jié)構(gòu)

考慮到一個宿舍的人員是有限的,所以可以用鏈表進行存儲。宿舍的人員設(shè)計為結(jié)構(gòu)體變量:

structsinger{undefined

longlNum;

charname[20];

floatfScore[10];

floatsum1,sum2,max,min,average;

structsinger*pNext;

};

其中包含選手編號、姓名、評委打分、總分(去除最高分和最低分)、最高分數(shù)、最低分數(shù)和平均分。然后我們在主函數(shù)當中定義一個結(jié)構(gòu)指針structsinger*spHead,作為鏈表的頭結(jié)點,然后依次創(chuàng)建下一個結(jié)構(gòu)體對他們進行遍歷輸入存儲。

3.功能的設(shè)計

函數(shù)功能的介紹

接收選手數(shù)據(jù):structsinger*CreatLiList(void);

評委打分:voidscore(structsinger*);

遍歷輸出數(shù)歌手數(shù)據(jù):voidTraverLiList(structsinger*);

追加選手數(shù)據(jù):intAppendNode(structsinger*,long,char*,float*);

刪除數(shù)據(jù):intDeleteNode(structsinger*,long);

搜索數(shù)據(jù):intSearchNode(structsinger*,long);

退出系統(tǒng),刪除鏈表數(shù)據(jù):structsinger*ReleaseLiList(structsinger*);

鏈表數(shù)據(jù)根據(jù)平均分排序:structsinger*SortList(structsinger*);

將數(shù)據(jù)寫入文件:將數(shù)據(jù)寫入文件:voidinput(structsinger*);

(1)輸入選手數(shù)據(jù)

用戶選擇功能1之后,我們對輸入的歌手的編號和姓名進行統(tǒng)計存儲,直到用戶輸入-1時,我們默認接受數(shù)據(jù)完畢,返回主程序功能頁面。

(2)評委打分

用戶選擇功能1之后,我們要根據(jù)用戶輸入的歌手的編號先對鏈表進行查找,如果歌手編號輸入錯誤,則提醒用戶重新輸入。找到該歌手之后,提醒用戶輸入的10評委的打分成績,同時將他們存進結(jié)構(gòu)體里面的數(shù)組,我們一邊接受一邊對成績進行統(tǒng)計,將總分最高分和最低分計算出來,然后用總分減去最高分和最低分,然后除以8得到歌手的實際平均分數(shù),這將作為我們下一步進行排序的重要依據(jù)。

(3)成績排序(按平均分)

根據(jù)第二部統(tǒng)計出的平均分數(shù),我們對鏈表數(shù)據(jù)進行插入排序。

思路:插入排序,顧名思義就是在兩個節(jié)點之間插入另一個節(jié)點,并且保持序列是有序的。如果當前要將節(jié)點cur插入到節(jié)點pre之后,我們只需要知道cur的前驅(qū)和插入位置(其實就是要插在哪個節(jié)點之后)就可以了。

(4)歌手數(shù)據(jù)查詢

根據(jù)輸入編號,對鏈表進行遍歷循環(huán),直到找到相應(yīng)的歌手編號,并對他的成績和個人信息進行輸出。

(5)追加選手數(shù)據(jù)

輸入待追加的選手編號,我們將開辟在鏈表的最后開辟新的結(jié)構(gòu)體變量內(nèi)存單元,并對選手的姓名和評分進行錄入。

(6)寫入數(shù)據(jù)文件

我們對歌手信息進行接受整理和排序之后將歌手的信息存入桌面下的txt文件中例如:C:\\Users\\fengling\\Desktop\\歌手比賽打分數(shù)據(jù)統(tǒng)計.txt。這樣可以在桌面打開,然后查看歌手排序好的信息。

(7)遍歷顯示數(shù)據(jù)

考慮到對歌手的信息可能進行多次的修改,我們要檢測程序運行的準確性。所以每一步操作之后,都可以選擇功能7,對選手數(shù)據(jù)進行遍歷輸出。

(8)刪除選手數(shù)據(jù)

考慮到對歌手可能退賽并沒有參加比賽也沒有相應(yīng)的分數(shù),所以我們可以從鏈表中刪除該選手的編號和姓名信息,達到節(jié)約內(nèi)存、方便顯示管理的目的。

(9)退出系統(tǒng)

退出系統(tǒng)時對鏈表內(nèi)存進行釋放,然后結(jié)束退出程序循環(huán)。

#includeiostream

#includeiomanip

#includecstdlib

#includefstream

#includestring

usingnamespacestd;

structsinger{

longlNum;

charname[20];

floatfScore[10];

floatsum1,sum2,max,min,average;

structsinger*pNext;

constintSIZE=

sizeof(structsinger);

//界面優(yōu)化

classInterface

private:

intline;//操作數(shù)的行數(shù)

string*name;

staticintnowline;

public:

voidGetMessage(intline1,string*name1)

{

line=line1;

name=newstring[line];

name=name1;

}

staticvoidAddNowLine()

{

nowline++;

}

voidShowHead()

{

ShowSpace();

for(inti=0;ii++)

{

if(i==0)

cout"╔";

else

{

if(i==49)

cout"╗";

else

cout"═";

}

}

coutendl;

AddNowLine();

}

voidShowSpace()

{

for(intx=0;xx++)

cout"";

}

voidShowOrderLine(intx)

{

int*number=newint[line];

for(inti=0,j=1;iline;j++,i++)

number[i]=j;

intlength;

length=name[x].length();

cout"║";

coutnumber[x]'.';

for(inttemp=0;temp46-length;temp++)//46-length==48-length-2

cout"-";

coutname[x];

cout"║";

}

voidShowSpaceLine()

{

cout"║";

for(intk=0;kk++)

cout"";

cout"║"endl;

}

voidShowEmptyLine()

{

if(nowline14)

{

for(inti=nowline;ii++)

{

ShowSpace();

AddNowLine();

ShowSpaceLine();

AddNowLine();

}

}

}

voidShowBody()

{

for(inti=0,j=1;iline;i++,j++)

{

ShowSpace();//前排的空格

AddNowLine();

ShowOrderLine(i);

coutendl;

ShowSpace();//前排的空格

AddNowLine();

ShowSpaceLine();

}

}

voidShowReturn()

{

ShowSpace();

AddNowLine();

cout"║9.";

for(inti=0;ii++)

cout"-";

cout"退出║"endl;

}

voidShowEndLine()

{

ShowSpace();

for(inti=0;ii++)

{

if(i==0)

cout"╚";

else

{

if(i==49)

cout"╝";

else

cout"═";

}

}

coutendl;

AddNowLine();

}

voidShowSurface()

{

ShowHead();

ShowBody();

ShowEmptyLine();

ShowReturn();

ShowEndLine();

}

intInterface::nowline=0;

//接收選手數(shù)據(jù)

structsinger*CreatLiList(void);

structsinger*CreatLiList(void)

structsinger*spHead,*spPre,*spCur;

longlv;

spPre=newstructsinger;

//spPre

=(structsinger*)malloc(SIZE);//頭結(jié)點

if(spPre==NULL){

returnNULL;

}

spHead=spPre;

spHead-pNext=NULL;

do{

cout"請輸入歌手編號:";

cinlv;

if(lv!=-1){

spCur=newstructsinger;

//spCur=(structsinger*)malloc(SIZE);

spCur-lNum=lv;

spCur-sum1=0;

getchar();

cout"請輸入姓名:";

cin.getline(spCur-name,20);

spCur-pNext=NULL;

spPre-pNext=spCur;

spPre=spCur;

}

}while(lv!=-1);//以-1結(jié)束。

returnspHead;

//評委打分

voidscore(structsinger*);

voidscore(structsinger*sp)

longlv;

structsinger*spCur;

do{

spCur=sp;

cout"輸入歌手編號:";

cinlv;

while(spCur-pNext!=NULLspCur-lNum!=lv)

{

spCur=spCur-pNext;

}

if(spCur-lNum==lv){

spCur-sum1=0;

cout"請輸入相應(yīng)10位評委成績:";

for(inti=0;ii++)

{

cinspCur-fScore[i];

spCur-sum1+=spCur-fScore[i];

if(i==0)

{

spCur-min=spCur-fScore[0];

spCur-max=spCur-fScore[0];

}

elseif(spCur-fScore[i]spCur-max)

{

spCur-max=spCur-fScore[i];

}

elseif(spCur-fScore[i]spCur-min)

{

spCur-min=spCur-fScore[i];

}

}

spCur-sum2=(spCur-sum1)-(spCur-max)-(spCur-min);

spCur-average=spCur-sum2/8.0f;

}

else

{

cout"歌手編號輸入錯誤,請重新";

}

}while(lv!=-1);//以-1結(jié)束。

//遍歷輸出數(shù)歌手數(shù)據(jù)

voidTraverLiList(structsinger*);

voidTraverLiList(structsinger*sp)

structsinger*spCur;

spCur=sp-pNext;

while(spCur!=NULL){

cout"ID:"setw(6)spCur-lNumendl;

cout"姓名:

"spCur-nameendl;

cout"十位評委打分成績?yōu)椋?endl;

for(inti=0;ii++)

cout"第"i+1"評委打分為:"setw(5)fixedsetprecision(1)spCur-fScore[i]endl;

cout"去除最高分和最低分的總分為:"spCur-sum2;

cout"

平均分數(shù)為:"spCur-averageendl;

coutendl;

spCur=spCur-pNext;

}

//追加選手數(shù)據(jù)

intAppendNode(structsinger*,long,char*,float*);

intAppendNode(structsinger*sp,longlArg,char*m,float*fArg)

structsinger*spCur,*spNew;

spCur=sp;

inti=0,j=0;

while(spCur-pNext!=NULL){

spCur=spCur-pNext;

}

spNew=newstructsinger;

if(spNew==NULL){

return1;

}

spNew-lNum=lArg;

for(m,j;*m;m++,j++)

{

spNew-name[j]=*m;

}

spNew-name[j]='\0';

for(i=0;ii++)

{

spNew-fScore[i]=fArg[i];

}

for(i=0;ii++)

{

spNew-sum1+=spNew-fScore[i];

if(i==0)

{

spNew-min=spNew-fScore[0];

spNew-max=spNew-fScore[0];

}

elseif(spNew-fScore[i]spNew-max)

{

spNew-max=spNew-fScore[i];

}

elseif(spNew-fScore[i]spNew-min)

{

spNew-min=spNew-fScore[i];

}

}

spNew-sum2=(spNew-sum1)-(spNew-max)-(spNew-min);

spNew-average=spNew-sum2/8.0f;

spNew-pNext=NULL;

spCur-pNext=spNew;

return0;

//刪除數(shù)據(jù)

intDeleteNode(structsinger*,long);

intDeleteNode(structsinger*sp,longlArg)

structsinger*spCur,*spT;

spCur=sp;

while(spCur-pNext!=NULLspCur-pNext-lNum!=lArg){

spCur=spCur-pNext;

}

if(spCur-pNext==NULL){

return1;

}

spT=spCur-pNext;

spCur-pNext=spCur-pNext-pNext;

deletespT;//刪除歌手的數(shù)據(jù)

return0;

//搜索數(shù)據(jù)

intSearchNode(structsinger*,long);

intSearchNode(structsinger*sp,longlArg)

structsinger*spCur;

spCur=sp;

while(spCur-pNext!=NULLspCur-lNum!=lArg){

spCur=spCur-pNext;

}

if(spCur-lNum==lArg){

cout"ID:"setw(12)spCur-lNumendl;

cout"name:

"spCur-nameendl;

cout"評委成績?yōu)椋?endl;

for(inti=0;ii++)

{

cout

setw(8)fixedsetprecision(1)spCur-fScore[i]endl;

}

cout"去除最高分和最低分的總分為:"spCur-sum2;

cout"

平均分數(shù)為:"spCur-averageendl;

return0;

}

else

{

return1;

}

//退出系統(tǒng),刪除鏈表數(shù)據(jù)

structsinger*ReleaseLiList(structsinger*);

structsinger*ReleaseLiList(structsinger*sp)

structsinger*spCurr,*spPrv;

spPrv=sp;

while(spPrv-pNext!=NULL){

spCurr=spPrv-pNext;

deletespPrv;

spPrv=spCurr;

}

deletesp;

returnNULL;

//鏈表數(shù)據(jù)根據(jù)平均分排序

structsinger*SortList(structsinger*);

structsinger*SortList(structsinger*head){

if(!head||!head-pNext)

returnhead;

structsinger*dummy=NULL;

dummy=newsinger[1];

dummy-pNext=head;

structsinger*pre=head;//當前節(jié)點的前驅(qū)

structsinger*cur=head-pNext;

while(cur!=NULL){

structsinger*tmp=dummy;

if(pre-average=cur-average){//需要進行插入

while(tmp-pNext-averagecur-average)//從第一個節(jié)點開始尋找插入位置

tmp=tmp-pNext;//cur應(yīng)該插入在tmp后面

pre-pNext=cur-pNext;//斷開節(jié)點cur

cur-pNext=tmp-pNext;//插入

tmp-pNext=cur;

cur=pre-pNext;//繼續(xù)處理下一個節(jié)點

}

else{//無需插入

pre=pre-pNext;

cur=cur-pNext;

}

}

cout"歌手按平均分排序成功!請選擇功能7遍歷查看。";

system("Pause");

returndummy-pNext;

}

//將數(shù)據(jù)寫入文件

voidinput(structsinger*);

voidinput(structsinger*sp)

fstreamoutFile;

outFile.open("C:\\Users\\fengling\\Desktop\\歌手比賽打分數(shù)據(jù)統(tǒng)計.txt",ios::out);

if(!outFile){

cout"Destinationfileopenerror!";

cout"文件寫入錯誤";

exit(1);

}

else

{

cout"文件寫入中......"endl;

}

structsinger*spCur;

spCur=sp-pNext;

while(spCur!=NULL){

outFile"ID:"setw(6)spCur-lNumendl;

outFile"姓名:

"spCur-nameendl;

outFile"十位評委打分成績?yōu)椋?endl;

for(inti=0;ii++)

outFile"第"i+1"評委打分為:"setw(5)fixedsetprecision(1)spCur-fScore[i]endl;

outFile"去除最高分和最低分的總分為:"spCur-sum2;

outFile"

平均分數(shù)為:"spCur-averageendl;

outFileendl;

spCur=spCur-pNext;

}

outFile.close();

cout"文件寫入成功!請在桌面下打開查看。";

system("Pause");

intmain(void)

structsinger*spHead=NULL;

intiIndex,iStatus=0;

longlID;

floatfScore[10];

system("color5E");

do{

system("CLS");

cout"

——————————*歌手評分系統(tǒng)*————————"endl;

Interfacex;

string*per=newstring[10];

per[0]="輸入選手數(shù)據(jù)";

per[1]="評委打分";

per[2]="成績排序(按平均分)";

per[3]="歌手數(shù)據(jù)查詢";

per[4]="追加選手數(shù)據(jù)";

per[5]="寫入數(shù)據(jù)文件";

per[6]="遍歷顯示數(shù)據(jù)";

per[7]="刪除選手數(shù)據(jù)";

x.GetMessage(8,per);

x.ShowSurface();

cout"輸入選擇項:";

ciniIndex;

switch(iIndex)

{

case1://輸入選手數(shù)據(jù)。

system("CLS");

if(spHead!=NULL){

ReleaseLiList(spHead);

spHead=NULL;

}

cout"以空格分隔輸入歌手遍號、姓名后回車確認(輸入-1結(jié)束)\n";

spHead=CreatLiList();

break;

case2://評委打分。

system("CLS");

if(spHead==NULL){

cout"歌手數(shù)據(jù)未錄入,請選擇1輸入數(shù)據(jù)!";

system("Pause");

break;

}

score(spHead);

break;

case3://成績排序。

system("CLS");

if(spHead==NULL){

cout"歌手數(shù)據(jù)未錄入,請選擇1輸入數(shù)據(jù)!";

system("Pause");

break;

}

SortList(spHead);

break;

case4://數(shù)據(jù)查詢。

system("CLS");

if(spHead==NULL){

cout"歌手信息未錄入,請選擇1輸入數(shù)據(jù)!";

system("Pause");

break;

}

cout"輸入需要查找的歌手編號:";

cinlID;

iStatus=SearchNode(spHead,lID);

if(iStatus==1){

cout"TheIdisnotfound!\n";

}

system("Pause");

break;

case5://追加選手數(shù)據(jù)。

system("CLS");

if(spHead==NULL){

cout"歌手信息未錄入,請選擇1輸入數(shù)據(jù)!";

system("Pause");

break;

}

charstr[20];

cout"請輸入編號:";

cinlID;

getchar();

cout"請輸入姓名:";

cin.getline(str,80);

cout"請輸入分數(shù):";

for(inti=0;ii++)

{

cinfScore[i];

}

iSta

溫馨提示

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

評論

0/150

提交評論