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

📄 sports.cpp

📁 运动会成绩管理程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>

typedef struct Info{
	char sportname_0[20];
	int sportnum_0;
	int schoolnum_0;
	int playernum_0;
	int point_0;
	char sex;
	struct Info *next;
}Info;

typedef struct FileInfo{
	char sportname_1[20];
	int sportnum_1;
	int schoolnum_1;
	int playernum_1;
	char sex;
	int point_1;
}FileInfo;

typedef struct evitem{
	int it_num;
	char it_name[20];
	int it_score;
}evitem;

typedef struct school{
	char sch_name[20];
	int sch_num;
	int score;
	int Mscore;
	int Fescore;
	evitem evit[20];
}school;

typedef struct List{
	char Listname_0[20];
	int Listnum_1;
	struct List *next;
}List;

typedef struct FileItem{
	int num_1;
	char itemname_1[20];
}FileItem;


	school sch[15];
	int qq;

 //***************************************************************************************
 //***************************************************************************************
 void Edit(void)
 {
	 fstream file,file_0;
	 int i,j,flag,num0,nn;
	 List *shead,*ihead,*p,*q;
	 char choice[20],choice0[20],name0[20],name1[20];
	 while(1){
		 system("cls");

		 file.open("schlist.txt",ios::in|ios::nocreate);
		 flag=0;
		 p=new List[1];
		 shead=p;
		 q=p;
		 file.getline(name0,20,'\n');
		 nn=atoi(name0);
		 file.getline(name1,20,'\n');
		 j=0;
		 while(!file.eof())
		 {
			 p=q;
			 (*q).Listnum_1=nn;
			 strcpy((*q).Listname_0,name1);
			 sch[j].sch_num=nn;
			 strcpy(sch[j].sch_name,name1);
			 j++;
			 file.getline(name0,20,'\n');
			 nn=atoi(name0);
			 file.getline(name1,20,'\n');
			 q=new List[1];
			 (*p).next=q;
			 flag=1;
		 }
		 if(flag==0)
			 shead=NULL;
		 (*p).next=NULL;
		 file.close();

		 file.open("itemlist.txt",ios::in|ios::nocreate);
		 flag=0;
		 p=new List[1];
		 ihead=p;
		 q=p;
		 file.getline(name0,20,'\n');
		 nn=atoi(name0);
		 file.getline(name1,20,'\n');
		 while(!file.eof())
		 {
			 p=q;
			 (*q).Listnum_1=nn;
			 strcpy((*q).Listname_0,name1);
			 for(i=0;i<15;i++){
				 sch[i].evit[nn].it_num=nn;
				 strcpy(sch[i].evit[nn].it_name,name1);
			 }
			 file.getline(name0,20,'\n');
			 nn=atoi(name0);
			 file.getline(name1,20,'\n');
			 q=new List[1];
			 (*p).next=q;
			 flag=1;
		 }
		 if(flag==0)
			 ihead=NULL;
		 (*p).next=NULL;
		 file.close();

		 cout<<endl<<endl;
		 q=ihead;
		 if(q==NULL)
			 cout<<"              项目列表为空!"<<endl;
		 else
			 cout<<"              项目列表:"<<endl;
		 while(q!=NULL)
		 {
			 cout<<"              "<<(*q).Listnum_1<<". ";
			 cout<<"  "<<(*q).Listname_0<<endl;
			 q=(*q).next;
		 }
		 
		 cout<<endl<<endl;
		 q=shead;
		 if(q==NULL)
			 cout<<"              学校列表为空!"<<endl;
		 else
			 cout<<"              学校列表:"<<endl;
		 while(q!=NULL)
		 {
			 cout<<"              "<<(*q).Listnum_1<<". ";
			 cout<<"  "<<(*q).Listname_0<<endl;
			 q=(*q).next;
		 }
		 cout<<endl<<endl;
		 cout<<"          ---------------------------------------"<<endl;
		 cout<<"                        成绩编辑"<<endl<<endl;
		 cout<<"                      1.   输入选手成绩;"<<endl;
		 cout<<"                      2.   删除选手成绩;"<<endl;
		 cout<<"                      3.   返回主菜单;"<<endl;
		 cout<<"                         请输入: ";
		 cin.getline(choice,81,'\n');

		 if(strcmp(choice,"1")==0){
				FileInfo *pointt;
				pointt=new FileInfo[1];
				cout<<endl<<endl;
				cout<<"    项目编号: ";
				cin>>nn;
				cout<<"    项目类型(男子【M】或女子【F】): ";
				cin>>(*pointt).sex;
				flag=0;
				q=ihead;
				while(q!=NULL){
					if((*q).Listnum_1==nn){
						cout<<"    项目: "<<(*q).Listname_0<<endl;
						flag=1;
						break;
					}
					q=(*q).next;
				}

				if(flag==0){
					cout<<"         没有此项目编号!!!"<<endl;
					cin.ignore();
					break;
				}

				file_0.open("point.txt",ios::out|ios::app|ios::binary);
				if(!file_0){
					cout<<endl<<endl;
					cout<<"    文件打开错误!";
					return;
				}

				cin.ignore();
				cout<<"    取前几名?(3 或 5)  ";
				cin.getline(choice0,81);
				if(strcmp(choice0,"3")==0)
					for(i=0;i<3;i++)
					{
						strcpy((*pointt).sportname_1,(*q).Listname_0);
						(*pointt).sportnum_1=(*q).Listnum_1;
						cout<<"  第"<<i+1<<"名:"<<endl;
						cout<<"         运动员编号: ";
						cin>>(*pointt).playernum_1;
						//cout<<"         性别: ";
						//cin>>(*pointt).sex;
						cout<<"         学校编号: ";
						cin>>(*pointt).schoolnum_1;
						switch(i+1)
						{
						case 1:(*pointt).point_1=5;break;
						case 2:(*pointt).point_1=3;break;
						case 3:(*pointt).point_1=2;break;
						}
						file_0.write((char*)pointt,sizeof(FileInfo));
					}
				if(strcmp(choice0,"5")==0)
					for(i=0;i<5;i++)
					{
						strcpy((*pointt).sportname_1,(*q).Listname_0);
						(*pointt).sportnum_1=(*q).Listnum_1;
						cout<<"  第"<<i+1<<"名:"<<endl;
						cout<<"         运动员编号: ";
						cin>>(*pointt).playernum_1;
						//cout<<"         性别: ";
						//cin>>(*pointt).sex;
						cout<<"         学校编号: ";
						cin>>(*pointt).schoolnum_1;
						switch(i+1)
						{
						case 1:(*pointt).point_1=7;break;
						case 2:(*pointt).point_1=5;break;
						case 3:(*pointt).point_1=3;break;
						case 4:(*pointt).point_1=2;break;
						case 5:(*pointt).point_1=1;break;
						}
						file_0.write((char*)pointt,sizeof(FileInfo));
					}
					file_0.close();
					cin.ignore();
					cout<<"     按任意键继续!"<<endl;
					cin.ignore();
					//cin.ignore();
			}//if 1
		 if(strcmp(choice,"2")==0){
			 FileInfo temp;
			 cout<<endl<<endl;
			 file.open("point.txt",ios::in|ios::out|ios::binary);
			 if(!file){
				 cout<<"     文件打开错误!"<<endl;
				 return;
			 }
			 cout<<"\t 请输入要删除的选手编号:";
			 cin>>num0;
			 cout<<"\t 请输入要删除的项目编号:";
			 cin>>nn;
			 flag=0;
			 file.read((char*)&temp,sizeof(temp));
			 while(!file.eof()){
				 if(num0==temp.playernum_1&&nn==temp.sportnum_1){
					 temp.playernum_1=0;
					 num0=(-1)*sizeof(temp);
					 file.seekp(num0,ios::cur);
					 file.write((char*)&temp,sizeof(temp));
					 flag=1;
					 cout<<"\t 删除成功!"<<endl;
					 break;
				 }//if
				 file.read((char*)&temp,sizeof(temp));
			 }//while
			 file.close();
			 if(flag==0)
				 cout<<"\t 不存在所要删除的记录!"<<endl;
			 cout<<"\t 按任意键继续!";
			 cin.ignore();
			 cin.ignore();
		 }//if 2
		 if(strcmp(choice,"3")==0){
					cout<<endl<<endl;
					return;
				}//if 4
		 if(strcmp(choice,"1")!=0&&strcmp(choice,"2")!=0&&strcmp(choice,"3")!=0){
			 cout<<endl;
			 cout<<"                  您输入的选择不正确!请重新输入!"<<endl;
			 cout<<"                        按任意键继续!";
			 cin.ignore();
		 }//if
	 }//while
 }//Edit
 //***************************************************************************************
 //***************************************************************************************

int Partition(int low,int high,char mark[20])
{
	school ooo;
	ooo=sch[low];
	
	if(strcmp(mark,"num")==0){
		while(low<high){
			while(low<high&&ooo.sch_num<=sch[high].sch_num)
				high--;
			sch[low]=sch[high];
			
			while(low<high&&ooo.sch_num>=sch[low].sch_num)
				low++;
			sch[high]=sch[low];
		}//while
		sch[low]=ooo;
		
	}

	if(strcmp(mark,"score")==0){
		while(low<high){
			while(low<high&&ooo.score>=sch[high].score)
				high--;
			sch[low]=sch[high];
			
			while(low<high&&ooo.score<=sch[low].score)
				low++;
			sch[high]=sch[low];
		}//while
		sch[low]=ooo;
		
	}
	
	if(strcmp(mark,"item")==0){
		while(low<high){
			while(low<high&&ooo.evit[qq].it_score>=sch[high].evit[qq].it_score)
				high--;
			sch[low]=sch[high];
			
			while(low<high&&ooo.evit[qq].it_score<=sch[low].evit[qq].it_score)
				low++;
			sch[high]=sch[low];
		}//while
		sch[low]=ooo;
		
	}

	if(strcmp(mark,"fscore")==0){
		while(low<high){
			while(low<high&&ooo.Fescore>=sch[high].Fescore)
				high--;
			sch[low]=sch[high];
			
			while(low<high&&ooo.Fescore<=sch[low].Fescore)
				low++;
			sch[high]=sch[low];
		}//while
		sch[low]=ooo;
	}

	if(strcmp(mark,"mscore")==0){
		while(low<high){
			while(low<high&&ooo.Mscore>=sch[high].Mscore)
				high--;

⌨️ 快捷键说明

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