首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

高手来抢分啊同时就小弟我一命~

2012-02-25 
高手来抢分啊!!!同时就我一命~~~~~~我想做一个英超积分榜,编了这个程序却不能实现我想要的功能,我找不出哪

高手来抢分啊!!!同时就我一命~~~~~~
我想做一个英超积分榜,编了这个程序却不能实现我想要的功能,我找不出哪里出错~~希望高手帮忙。不能改我的类结构,就是不能删去任何一个类
#include <iostream>
#include <strstream>
#include <conio.h>
#include <math.h>
#include <iomanip>
#include <string>
using   namespace   std;
class   team
{
public:
static   int   points;
static   int   score;
static   int   lose;
static   int   win;
static   int   tie;
static   int   failed;
team(char   *s);
team();
team   *next;
char   name[10];
};                                                                     //team类
int   team::points=0;
int   team::score=0;
int   team::lose=0;
int   team::win=0;
int   team::tie=0;
int   team::failed=0;
team::team(char   *   s)
{
strcpy(name,s);
}
team::team()
{
}
class   match
{
public:
match(){}
        void   result(int   ,int);
int   getz();
private:
int   z;
};
void   match::result(int   x   ,int   y)
{
if(x> =y)
        if(x> y)z=3;
        else   z=1;
        else   z=0;
}
int   match::getz()
{
return   z;
}
class   footballmatch:public   match
{
public:
        footballmatch(char   *str);
        void   showresult();
team   team1,team2;
private:
int   v;
};
footballmatch::footballmatch(char   *str)
{
char   s1[10],s2[10],s3[10];
        int   a,b;
        istrstream   input(str);
        input> > s1> > a> > s2> > b> > s3;
result(a,b);
        strcpy(team1.name,s1);
        strcpy(team2.name,s3);
        team1.score=a;
        team1.lose=b;
        team2.score=b;
        team2.lose=a;
        v=abs(a-b);
}
void   footballmatch::showresult()                                                             //有时间这里搞成多态
{
if(match::getz()> =1)
if(match::getz()> 1)
{
if(v> =3)cout < <team1.name < < "以 " < <team1.score < < ": " < <team2.score < < "大胜 " < <team2.name < <endl;
                else   cout < <team1.name < < "以 " < <team1.score < < ": " < <team2.score < < "击败 " < <team2.name < <endl;
}
        else   cout < <team1.name < < "与 " < <team2.name < <team1.score < < ": " < <team2.score < < "握手言和 " < <endl;
        else  
{
if(v> =3)cout < <team1.name < < "以 " < <team1.score < < ": " < <team2.score < < "惨败于 " < <team2.name < <endl;


                else   cout < <team1.name < < "以 " < <team1.score < < ": " < <team2.score < < "不敌 " < <team2.name < <endl;
}
}
class   leadge:public   footballmatch
{
public:
leadge(char   *);
        void   reflesh(team   *&head);
};
leadge::leadge(char   *s):footballmatch(s)
{
}
void   leadge::reflesh(team   *   &head)
{
for(team   *q=head;q-> next;q=q-> next)
{      
if(!strcmp(q-> name,team1.name))
{
        q-> score+=team1.score;
        q-> lose+=team1.lose;
q-> points+=match::getz();
if(getz()> =1)
if(getz()> 1)q-> win+=1;
else   q-> tie+=1;
                                else   q-> failed+=1;
for(team   *p=head;p-> next;p=p-> next)
{
                if(!strcmp(p-> name,team2.name))
{      
                      p-> score+=team2.score;
                p-> lose+=team2.lose;
p-> points+=match::getz();
                if(getz()> =1)
                if(getz()> 1)p-> win+=1;
                else   p-> tie+=1;
                                                else   p-> failed+=1;
}
}
break;
}
}
}

void   main()
{
int   m=1;
int   j=0;
static   int   k=1;
team   *head=NULL;
team   *head1=NULL;
cout < < "                                           欢迎使用 " < <endl;
while(m)
{
                cout < < "请选择你想要做的事 " < <endl;
                cout < < "输入1为激活本赛季英格兰足球超级联赛 " < <endl;
cout < < "输入2为更新联赛数据 " < <endl;
cout < < "输入3为列出目前的积分榜 " < <endl;
cout < < "输入4为激活本赛季英格兰足总杯 " < <endl;
cout < < "输入5为更新足总杯战况 " < <endl;
cout < < "输入6为显示现阶段仍未淘汰的球队 " < <endl;
cout < < "输入0为退出 " < <endl;
cin> > m;
switch(m)
{
case   1:
                        if(j==1)
{
                cout < < "已经知道有哪些球队了 " < <endl;
                        break;
}
                else
{
team   ars( "ars ");
                                team   manu( "manu ");


                team   che( "che ");
                team   liv( "liv ");
                head=&ars;
                        ars.next=&manu;
                        manu.next=&che;
                        che.next=&liv;
                        liv.next=NULL;
                        j=1;
                cout < < "已经开赛啦 " < <endl;
}
break;
case   2:
char   l;
                if(j==0)
{
                cout < < "还不知道有哪些球队,先去搞掂再来吧。 " < <endl;
                        return;
}
                else
{
                cout < < "请输入第 " < <k < < "轮比赛结果 " < <endl;
                        cout < < "如:阿森纳2:1赢了曼联,你就输入:   ars   2   :   1   manu " < <endl;
                        cout < < "懂了吗? " < < "(y/n) " < <endl;
                        cin> > l;
                        if(l== 'n ')
{
        cout < < "就你这种资质还是不要用好了。 " < <endl;
                        return;
}
                        else
{
                cout < < "那你就开始输入吧 " < <endl;
                for(int   h=0;h <2;h++)
{
                char   *s=new   char[40];
                cgets(s);
                leadge   england(s+2);
                england.reflesh(head);
                england.showresult();
delete   []s;
s=NULL;
}
                k++;
                int   w;
                for(int   p=1;p <4;p++)
{
                                                w=1;
                for(team   *u=head;u-> next;u=u-> next)


{
                team   *v=u-> next;
                if(u-> points <v-> points)
{
                u-> next=v-> next;
                v-> next=u;
                w=0;
}
}
                if(w)break;
}
}
}
break;
case   3:
if(k-1==0)
{
                cout < < "英超还没开打,你急什么? " < <endl;
                return;
}
                else
{
                cout < < "英超积分榜(截止至第 " < <k-1 < < "轮) " < <endl;
                cout.setf(ios::left);
                cout < <setw(3) < < "P "
                < <setw(8) < < "NAME "
                < <setw(3) < < "M "
                < <setw(3) < < "W "
                < <setw(3) < < "T "
                < <setw(3) < < "L "
                < <setw(3) < < "I "
                < <setw(3) < < "O "
                  < <setw(3) < < "Y "
                < <setw(3) < < "Pos "
                < <endl;
              team   *p=head;
              int   i=1;
              while(p)
      {
              cout < <setw(3) < <i
                      < <setw(8) < <p-> name
                      < <setw(3) < <k-1
                      < <setw(3) < <p-> win
                      < <setw(3) < <p-> tie
                      < <setw(3) < <p-> failed
                      < <setw(3) < <p-> score
                      < <setw(3) < <p-> lose
                      < <setw(3) < <p-> score-head-> lose
                      < <setw(3) < <p-> points


                      < <endl;
                i++;
                p=p-> next;
      }
              delete   p;
              p=NULL;
}
break;
case   0:
break;
}
}
}
关于这个程序有什么不清楚的地方请加我Q763233626我详细解释,谢谢啦

[解决办法]
把static成员全改成非static的,你的team1和team2中的静态数据永远是相等的.

team就做成一个简单的team,不要还用一个team* next,这样这个类表示的概念太复杂,不容易理解.

如果需要list功能,到标准库中找vector和list,vector可能更好.
[解决办法]
#include <iostream>
#include <strstream>
#include <conio.h>
#include <math.h>
#include <iomanip>
#include <string>
using namespace std;
class team{
public:
int points;
int score;
int lose;
int win;
int tie;
int failed;
team(char *s);
team():points(0),score(0),lose(0),win(0),tie(0),failed(0){};
team *next;
char name[10];
}; //team类

team::team(char * s)
:points(0),score(0),lose(0),win(0),tie(0),failed(0)
{
strcpy(name,s);
}

class match{
public:
match():z(0){}
void result(int ,int);
int getz();
private:
int z;
};

void match::result(int x ,int y)
{
if(x> =y)
if(x> y)z=3;
else z=1;
else z=0;
}

int match::getz()
{
return z;
}

class footballmatch:public match{
public:
footballmatch(char *str);
void showresult();
team team1,team2;
private:
int v;
};

footballmatch::footballmatch(char *str)
{
char s1[10],s2[10],s3[10];
int a,b;
istrstream input(str);
input> > s1> > a> > s2> > b> > s3;
strcpy(team1.name,s1);
strcpy(team2.name,s3);
team1.score=a;
team1.lose=b;
team2.score=b;
team2.lose=a;
result(a,b);
switch(getz()){
case 3:
team1.points = 3;
team1.win =1;
team2.failed=1;
break;
case 1:
team1.points=1;
team2.points=1;
team1.tie=1;
team2.tie=1;
break;
case 0:
team1.failed=1;
team2.points = 3;
team2.win =1;
}
v=abs(a-b);
}

void footballmatch::showresult() //有时间这里搞成多态
{
int zm = getz();
cout < < zm < <endl;
if(zm> =1)
if(zm> 1){
if (v> =3)
cout < <team1.name < < "以 " < <team1.score < < ": " < <team2.score < < "大胜 " < <team2.name < <endl;
else
cout < <team1.name < < "以 " < <team1.score < < ": " < < team2.score < < "击败 " < <team2.name < <endl;
}
else
cout < <team1.name < < "与 " < <team2.name < < team1.score < < ": " < <team2.score < < "握手言和 " < <endl;
else{
if (v> =3)
cout < <team1.name < < "以 " < <team1.score < < ": " < <team2.score < < "惨败于 " < <team2.name < <endl;
else


cout < <team1.name < < "以 " < <team1.score < < ": " < < team2.score < < "不敌 " < <team2.name < <endl;
}
}

class leadge:public footballmatch{
public:
leadge(char *);
void reflesh(team *&head);
};

leadge::leadge(char *s):footballmatch(s)
{
}
void leadge::reflesh(team * &head)
{
for(team *q=head;q;){
if(!strcmp(q-> name,team1.name)){
q-> score+=team1.score;
q-> lose+=team1.lose;
q-> points+=team1.points;//match::getz();
q-> win+= team1.win;
q-> failed +=team1.failed;
q-> tie+=team1.tie;
//break;
}
if(!strcmp(q-> name,team2.name)){
q-> score+=team2.score;
q-> lose+=team2.lose;
q-> points+=team2.points;
q-> win+= team2.win;
q-> failed +=team2.failed;
q-> tie+=team2.tie;
//break;
}
q=q-> next;
}
}

char* GetS(char **str)
{
string s,s1;
cin > > s;
for(int i=0;i <4;i++){
cin > > s1;
s += " "+s1;}
return strcpy(*str,s.c_str());
}

void main()
{
int m=1;
int j=0;
static int k=1;
team *head=NULL;
team *head1=NULL;
cout < < " 欢迎使用 " < <endl;
while(m){
cout < < "请选择你想要做的事 " < <endl;
cout < < "输入1为激活本赛季英格兰足球超级联赛 " < <endl;
cout < < "输入2为更新联赛数据 " < <endl;
cout < < "输入3为列出目前的积分榜 " < <endl;
cout < < "输入4为激活本赛季英格兰足总杯 " < <endl;
cout < < "输入5为更新足总杯战况 " < <endl;
cout < < "输入6为显示现阶段仍未淘汰的球队 " < <endl;
cout < < "输入0为退出 " < <endl;
cin> > m;
switch(m){
case 1:
if(j==1){
cout < < "已经知道有哪些球队了 " < <endl;
break;}
else{
team *ars = new team( "ars ");
team *manu = new team( "manu ");
team *che = new team( "che ");
team *liv = new team( "liv ");
head=ars;
ars-> next=manu;
manu-> next=che;
che-> next=liv;
liv-> next=NULL;
j=1;
cout < < "已经开赛啦 " < <endl;}
break;
case 2:
char l;
if(j==0){
cout < < "还不知道有哪些球队,先去搞掂再来吧。 " < <endl;
return;}
else{
cout < < "请输入第 " < <k < < "轮比赛结果 " < <endl;
cout < < "如:阿森纳2:1赢了曼联,你就输入: ars 2 : 1 manu " < <endl;
cout < < "懂了吗? " < < "(y/n) " < <endl;
cin> > l;
if(l== 'n '){
cout < < "就你这种资质还是不要用好了。 " < <endl;
return;}
else{
cout < < "那你就开始输入吧 " < <endl;
for(int h=0;h <2;h++){
char *s=new char[40];
GetS(&s);
leadge england(s);
england.reflesh(head);
england.showresult();
delete []s;
//s=NULL;
}
k++;
/*
int w;
for(int p=1;p <4;p++){
w=1;
for(team *u=head;u-> next;u=u-> next){
team *v=u-> next;
if(u-> points <v-> points){
u-> next=v-> next;
v-> next=u;
w=0;}}
if(w)break;}


*/
}
}
break;
case 3:
if(k-1==0){
cout < < "英超还没开打,你急什么? " < <endl;
return;}
else{
cout < < "英超积分榜(截止至第 " < <k-1 < < "轮) " < <endl;
cout.setf(ios::left);
cout < <setw(3) < < "P "
< <setw(8) < < "NAME "
< <setw(3) < < "M "
< <setw(3) < < "W "
< <setw(3) < < "T "
< <setw(3) < < "L "
< <setw(3) < < "I "
< <setw(3) < < "O "
< <setw(3) < < "Y "
< <setw(3) < < "Pos "
< <endl;
team *p=head;
int i=1;
while(p){
cout < <setw(3) < <i
< <setw(8) < <p-> name
< <setw(3) < <k-1
< <setw(3) < <p-> win
< <setw(3) < <p-> tie
< <setw(3) < <p-> failed
< <setw(3) < <p-> score
< <setw(3) < <p-> lose
< <setw(3) < <p-> score-head-> lose
< <setw(3) < <p-> points
< <endl;
i++;
p=p-> next;}
//delete p;
//p=NULL;
}
break;
case 0:
for(team *p=head;p;){
team *t = p;p=p-> next;
delete t;}
break;
}
}
}

热点排行