⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.cpp

📁 这是个运动会记分程序,不知道大家感兴趣不,不过我觉得是我自己写的
💻 CPP
字号:
//试验目的:这是个运动会记分程序
//作者:高天鹏  班级:计046   学号:2004041258
//最后修改时间:2005.06.27
#include <iostream>
#include <string>
using namespace std;

typedef struct//这个结构体是用来存放各个运动员的情况
{
	string m_strPlayerName;//用来存放运动员的名字
	short m_uSchoolID;//用来存放学校的编号
}PLAYERINFO;

typedef struct //这个结构体是用来对存放各个项目的情况
{
    short m_nType;//取分方法的类型
	PLAYERINFO *m_player;//指向运动员的指针(其为结构体类型)
}ITEMINFO;

const order0[] = {5,3,2};//把运动员的得分定为常量
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:计046"<<"      "<<"number:2004041258"<<endl;//显示作者信息
	cout<<"please enter the data according to the request ";//按要求输入数据
	cout<<endl<<"please enter the number of school:";//下面是用户输入要求数据(学校.项目个数)
	//请输入参赛学校的个数
	cin>>nSchool;
	string *pScl = new string[nSchool];//创建动态数组
	cout<<endl<<"please enter the name of school:";
	for (i=0;i<nSchool;++i)
	{
		cout<<endl<<"number"<<i<<":";//请一次输入学校的名称
		cin>>pScl[i];//存放在动态数组里
	}

	cout<<endl<<endl;

	cout<<endl<<"please enter the total of man:";//请输入男子组比赛项目总数
	cin>>nMan;
	cout<<endl<<"please enter the total of woman:";//请输入女子组比赛项目总数
	cin>>nWoman;
	cout<<endl;

	ITEMINFO *pItem = new ITEMINFO[nMan+nWoman];//创建动态结构体
	
	for (i=0;i<nMan+nWoman;++i)//循环所有运动项目
	{
		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];//创建动态数组
		for (j=0;j<nCnt;++j)//循环输入每个项目中运动员信息(按名次)
		{
			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;//下面是输出实现
		do{                    //请用户选择输出类型

		        cout<<"1.the score of all item"<<endl;//显示所有项目运动员成绩
		        cout<<"2.school report card for each"<<endl;//查看各个学校成绩单
	            cout<<"3.output the scores"<<endl;//输出团体成绩表
				cout<<"4.the all"<<endl;//输出全部数据
		        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;//运动员姓名
				                                      cout<<"\t\tschool:"<<pScl[pItem[i].m_player[j].m_uSchoolID]<<endl;//运动运学校
				                                      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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -