?? 1.cpp
字號:
//試驗(yàn)?zāi)康?這是個運(yùn)動會記分程序
//作者:高天鵬 班級:計(jì)046 學(xué)號:2004041258
//最后修改時(shí)間:2005.06.27
#include <iostream>
#include <string>
using namespace std;
typedef struct//這個結(jié)構(gòu)體是用來存放各個運(yùn)動員的情況
{
string m_strPlayerName;//用來存放運(yùn)動員的名字
short m_uSchoolID;//用來存放學(xué)校的編號
}PLAYERINFO;
typedef struct //這個結(jié)構(gòu)體是用來對存放各個項(xiàng)目的情況
{
short m_nType;//取分方法的類型
PLAYERINFO *m_player;//指向運(yùn)動員的指針(其為結(jié)構(gòu)體類型)
}ITEMINFO;
const order0[] = {5,3,2};//把運(yùn)動員的得分定為常量
const order1[] = {7,5,3,2,1};
int main()
{
int nMan,nWoman,nSchool;
int i,h,j,k;
char ans;
cout<<" "<<"The Keep the score for game using process"<<endl;
cout<<"name:高天鵬"<<" "<<"class:計(jì)046"<<" "<<"number:2004041258"<<endl;//顯示作者信息
cout<<"please enter the data according to the request ";//按要求輸入數(shù)據(jù)
cout<<endl<<"please enter the number of school:";//下面是用戶輸入要求數(shù)據(jù)(學(xué)校.項(xiàng)目個數(shù))
//請輸入?yún)①悓W(xué)校的個數(shù)
cin>>nSchool;
string *pScl = new string[nSchool];//創(chuàng)建動態(tài)數(shù)組
cout<<endl<<"please enter the name of school:";
for (i=0;i<nSchool;++i)
{
cout<<endl<<"number"<<i<<":";//請一次輸入學(xué)校的名稱
cin>>pScl[i];//存放在動態(tài)數(shù)組里
}
cout<<endl<<endl;
cout<<endl<<"please enter the total of man:";//請輸入男子組比賽項(xiàng)目總數(shù)
cin>>nMan;
cout<<endl<<"please enter the total of woman:";//請輸入女子組比賽項(xiàng)目總數(shù)
cin>>nWoman;
cout<<endl;
ITEMINFO *pItem = new ITEMINFO[nMan+nWoman];//創(chuàng)建動態(tài)結(jié)構(gòu)體
for (i=0;i<nMan+nWoman;++i)//循環(huán)所有運(yùn)動項(xiàng)目
{
cout<<endl<<"please enter the"<<i+1<<"item(5 or 3)(0:for 3,1:for 5):";
cin>>pItem[i].m_nType;
int nCnt = pItem[i].m_nType ? 5 : 3;//判斷用戶要求的取名次方式
cout<<endl<<"\t\tplease enter the name and the school of player by order .";
pItem[i].m_player = new PLAYERINFO[nCnt];//創(chuàng)建動態(tài)數(shù)組
for (j=0;j<nCnt;++j)//循環(huán)輸入每個項(xiàng)目中運(yùn)動員信息(按名次)
{
cout<<endl<<"\t\t\tplease enter"<<j+1<<"number of the name :";
cin>>pItem[i].m_player[j].m_strPlayerName;
cout<<endl<<"\t\t\tplease enter"<<j+1<<"number the name of school:";
cin>>pItem[i].m_player[j].m_uSchoolID;
}
}
cout<<endl<<endl;//下面是輸出實(shí)現(xiàn)
do{ //請用戶選擇輸出類型
cout<<"1.the score of all item"<<endl;//顯示所有項(xiàng)目運(yùn)動員成績
cout<<"2.school report card for each"<<endl;//查看各個學(xué)校成績單
cout<<"3.output the scores"<<endl;//輸出團(tuán)體成績表
cout<<"4.the all"<<endl;//輸出全部數(shù)據(jù)
cout<<"5.the last and over"<<endl; //退出
cout<<"please enter your choose"<<endl;//請選擇功能
cin>>h;
switch(h)//
{
int n,order;
case 1:
{
for (i=0;i<nMan+nWoman;++i)
{
cout<<"item"<<i+1<<"type:"<<pItem[i].m_nType<<endl;
n=pItem[i].m_nType?5:3;
for (j=0;j<n;++j)
{
order = pItem[i].m_nType ? order1[j] : order0[j];
cout<<"\tthe number"<<j+1;
cout<<"\t\tname:"<<pItem[i].m_player[j].m_strPlayerName<<endl;
cout<<"\t\tschool:"<<pScl[pItem[i].m_player[j].m_uSchoolID]<<endl;
cout<<"\t\tscore:"<<order<<endl;
}
}
}break;
case 2:
{
for (i=0;i<nSchool;++i)
{
cout<<endl<<"school:"<<pScl[i];
for (j=0;j<nMan+nWoman;++j)
{
cout<<endl<<"\titem"<<j<<":";
n=pItem[j].m_nType?5:3;
for (k=0;k<n;++k)
{
if (pItem[j].m_player[k].m_uSchoolID == i)
{
order = pItem[j].m_nType ? order1[k] : order0[k];
cout<<endl<<"\t\tplace in a competition:"<<k+1;
cout<<endl<<"\t\tname:"<<pItem[j].m_player[k].m_strPlayerName;
cout<<endl<<"\t\tscore:"<<order;
}
}
}
}
}break;
case 3:
{
int total1,total2;
for (i=0;i<nSchool;++i)
{
cout<<endl<<"school:"<<pScl[i];
total1 = 0;
for (j=0;j<nMan;++j)
{
n=pItem[j].m_nType?5:3;
for (k=0;k<n;++k)
if (pItem[j].m_player[k].m_uSchoolID == i)
total1 += pItem[j].m_nType?order1[k]:order0[k];
}
cout<<endl<<"\tthe total score of man:"<<total1;
total2 = 0;
for (j=nMan;j<nMan+nWoman;++j)
{
n=pItem[j].m_nType?5:3;
for (k=0;k<n;++k)
if (pItem[j].m_player[k].m_uSchoolID == i)
total2 += pItem[j].m_nType?order1[k]:order0[k];
}
cout<<endl<<"\tthe total score of woman:"<<total2;
cout<<endl<<"\tgroup total scores:"<<total1+total2;
}
}
break;
cout<<endl;
case 4:
{
cout<<"1.the score of all item"<<endl;
for (i=0;i<nMan+nWoman;++i)
{
cout<<"item"<<i+1<<"type:"<<pItem[i].m_nType<<endl;
n=pItem[i].m_nType?5:3;
for (j=0;j<n;++j)
{
order = pItem[i].m_nType ? order1[j] : order0[j];
cout<<"\tthe number"<<j+1;
cout<<"\t\tname:"<<pItem[i].m_player[j].m_strPlayerName<<endl;//運(yùn)動員姓名
cout<<"\t\tschool:"<<pScl[pItem[i].m_player[j].m_uSchoolID]<<endl;//運(yùn)動運(yùn)學(xué)校
cout<<"\t\tscore:"<<order<<endl;//成績
}
}
cout<<"2.school report card for each"<<endl;
for (i=0;i<nSchool;++i)
{
cout<<endl<<"school:"<<pScl[i];
for (j=0;j<nMan+nWoman;++j)
{
cout<<endl<<"\titem"<<j<<":";
n=pItem[j].m_nType?5:3;
for (k=0;k<n;++k)
{
if (pItem[j].m_player[k].m_uSchoolID == i)
{
order = pItem[j].m_nType ? order1[k] : order0[k];
cout<<endl<<"\t\tplace in a competition:"<<k+1;
cout<<endl<<"\t\tname:"<<pItem[j].m_player[k].m_strPlayerName;
cout<<endl<<"\t\tscore:"<<order;
}
}
}
}
cout<<endl;
cout<<"3.output the scores"<<endl;
int total1,total2;
for (i=0;i<nSchool;++i)
{
cout<<endl<<"school:"<<pScl[i];
total1 = 0;
for (j=0;j<nMan;++j)
{
n=pItem[j].m_nType?5:3;
for (k=0;k<n;++k)
if (pItem[j].m_player[k].m_uSchoolID == i)
total1 += pItem[j].m_nType?order1[k]:order0[k];
}
cout<<endl<<"\tthe total score of man:"<<total1;
total2 = 0;
for (j=nMan;j<nMan+nWoman;++j)
{
n=pItem[j].m_nType?5:3;
for (k=0;k<n;++k)
if (pItem[j].m_player[k].m_uSchoolID == i)
total2 += pItem[j].m_nType?order1[k]:order0[k];
}
cout<<endl<<"\tthe total score of woman:"<<total2;
cout<<endl<<"\tgroup total scores:"<<total1+total2;
}
}
break;
cout<<endl;
case 5:
break;
default:
break;
}
cout<<endl;
cout<<"Do you want to go on?; (y or Y show yes,n or N show NO)";
cin>>ans;
}while(ans =='Y'||ans == 'y');
cout<<endl;
for (i=0;i<nMan+nWoman;++i)
delete [] pItem[i].m_player;
delete [] pItem;
delete [] pScl;
return 0;
cout<<"the last,thank you"<<endl;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -