C++:足球联赛积分系统
2017-11-13 22:41
239 查看
#include<iostream> #include<iomanip> #include<string> #include<fstream> #include<stdlib.h> using namespace std; class Team { public: Team(char n[15],int s,int w,int d,int l,int g,int lo,int sc):sum(s),win(w),draw(d),lost(l),get(g),lose(lo),score(sc) { int i; for(i=0;i<15;i++) name[i]=n[i]; }; Team(){}; int sum,win,draw,lost,get,lose,score; char name[15]; Team operator +(Team &a) { sum=sum+1; get=get+a.get; lose=lose+a.lose; if(a.get>a.lose)win=win+1; else if(a.get==a.lose)draw=draw+1; else lost=lost+1; score=win*3+draw; return *this; }; void Dispaly() { cout<<setw(15)<<name<<setw(10)<<sum<<setw(10)<<win<<setw(10)<<draw<<setw(10)<<lost<<setw(10)<<get<<setw(10)<<lose<<setw(10)<<score<<endl; }; }; void Change(Team &a,Team &b) { Team c; c=a; a=b; b=c; }; void main() { cout<<endl<<endl<<endl; cout<<"□□□□□ □□□ □□□ □□□□□ □□□□ □ □□□ □□□ "<<endl; cout<<" □ □ □ □ □ □ □ □ □ □ □ □ □ □ "<<endl; cout<<" □ □ □ □ □ □ □ □ □ □□ □ □ "<<endl; cout<<" □□□ □ □ □ □ □ □□□ □ □ □ □ "<<endl; cout<<" □ □ □ □ □ □ □ □ □ □ □ □ □ "<<endl; cout<<" □ □ □ □ □ □ □ □ □□□□ □ b7e6 □ "<<endl; cout<<" □ □ □ □ □ □ □ □ □ □ □ □ □ □"<<endl; cout<<"□□□ □□□ □□□ □□□ □□□□ □□ □□□□□□□□□□□□□□"<<endl; cout<<endl<<"目前比赛的排名为:"<<endl<<endl;; cout<<setw(5)<<"名次"<<setw(15)<<"队名"<<setw(10)<<"比赛场数"<<setw(10)<<"胜场"<<setw(10)<<"平局"<<setw(10)<<"败场"<<setw(10)<<"进球"<<setw(10)<<"输球"<<setw(10)<<"总分"<<endl; ifstream in("score.txt"); if(!in) { cout<<"Unable to open in"; exit(1); } char name[15],a[3]; int sum,win,draw,lost,get,lose,score; int i,j; Team team[10]; for(i=0;i<10;i++) { in.get(a,2,' '); in.getline(name,15); in.clear(); in.get(a,4);sum=atoi(a); in.get(a,4);win=atoi(a); in.get(a,4);draw=atoi(a); in.get(a,4);lost=atoi(a); in.get(a,4);get=atoi(a); in.get(a,4);lose=atoi(a); in.get(a,4);score=atoi(a); Team t(name,sum,win,draw,lost,get,lose,score); team[i]=t; } in.close; for(i=0;i<9;i++) for(j=i+1;j<10;j++) if(team[i].score<team[j].score) Change(team[i],team[j]); for(i=0;i<10;i++) { cout<<setw(5)<<i+1; team[i].Dispaly(); } while(1) { cout<<endl<<"请输入新一轮的比赛结果:"<<endl<<endl; char name1[15],name2[15]; int get1,get2; cin>>name1>>name2>>get1>>get2; Team team1(name1,0,0,0,0,get1,get2,0); Team team2(name2,0,0,0,0,get2,get1,0); int t1=0,t2=0; int longth1=strlen(name1),longth2=strlen(name2); for(i=0;i<10;i++) { if(team[i].name[13]==team1.name[longth1-1]&&team[i].name[12]==team1.name[longth1-2]&&team[i].name[11]==team1.name[longth1-3]) t1=i; if(team[i].name[13]==team2.name[longth2-1]&&team[i].name[12]==team2.name[longth2-2]&&team[i].name[11]==team2.name[longth2-3]) t2=i; } team[t1]=team[t1]+team1; team[t2]=team[t2]+team2; for(i=0;i<9;i++) for(j=i+1;j<10;j++) if(team[i].score<team[j].score) Change(team[i],team[j]); cout<<endl<<"目前比赛的排名为:"<<endl<<endl;; cout<<setw(5)<<"名次"<<setw(15)<<"队名"<<setw(10)<<"比赛场数"<<setw(10)<<"胜场"<<setw(10)<<"平局"<<setw(10)<<"败场"<<setw(10)<<"进球"<<setw(10)<<"输球"<<setw(10)<<"总分"<<endl; for(i=0;i<10;i++) { cout<<setw(5)<<i+1; team[i].Dispaly(); } ofstream out("score.txt"); if(!out) { cout<<"Unable to open out"; exit(1); } for(i=0;i<10;i++) { out<<setw(15)<<team[i].name<<setw(10)<<team[i].sum<<setw(10)<<team[i].win<<setw(10)<<team[i].draw<<setw(10)<<team[i].lost<<setw(10)<<team[i].get<<setw(10)<<team[i].lose<<setw(10)<<team[i].score<<endl; } out.close; } }
相关文章推荐
- 足球联赛管理系统所有数据库对象
- c语言实现足球比赛积分统计系统
- C\C++时间处理函数[获取系统时间,求时间差,格式化输出等]
- 学生课程选修--图书管理系统(C++版)第一部分
- c++链表实现学生成绩管理系统(简易版)
- c/c++在windows系统下的环境配置
- C++第2周(春)项目3 文件+结构体实现实用系统
- c++简单的学生管理系统----继承练习
- 如何用C++代码检测你用的编程环境是64系统还是32位系统?
- C++检测系统是否已经安装了.NET Framework
- C++系统预定义4个用于标准数据流对象
- C++设计实例-----毕业生收入预测分析系统
- C++获取系统当前时间
- C/C++如何获取当前系统时间的实例详解
- C++获取系统图标方法
- c++ 如何获取系统时间
- c++thread学习(3)并发多线程系统开发过程
- C/C++模仿小灵通系统
- C++主要类型的长度(32位与64位系统比较)
- 用C++实现员工管理系统