C++题目,类与对象!求大神解答!
1个回答
展开全部
//exp3_2.h
#ifndef _SCORE_H
#define _SCORE_H
class Score
{
public:
Score();
Score(int,int);
~Score();
void Set(int,int);
int GetHometeam();
int GetOpponent();
void Display();
private:
int hometeam;
int opponent;
};
#endif
//exp3_2.cpp
#include"exp3_2.h"
#include<iostream>
Score::Score()
{
hometeam=0;
opponent=0;
}
Score::Score(int hometeam,int opponent)
{
this->hometeam=hometeam;
this->opponent=opponent;
}
Score::~Socre(){}
void Score::Set(int hometeam,int opponent)
{
this->hometeam=hometeam;
this->opponent=opponent;
}
int Score::GetHometeam()
{
return hometeam;
}
int Score::GetOpponent()
{
return opponent;
}
void Score::Display()
{
std::cout<<hometeam<<":"<<opponent<<std::endl;
}
void query(Score *game)
{
int t;
while(true)
{
std::cout<<"请输入比赛的场次(1~5,输入0退出查询):";
std::cin>>t;
if(t==0) break;
else game[t-1].Display();
}
}
void result(Score *p,Score &e)
{
int hometeam=0;
int opponent=0;
for(int i=0;i<5;i++)
{
hometeam+=p[i].GetHometeam();
opponent+=p[i].GetOpponent();
}
e.Set(hometeam,opponent);
}
int main(void)
{
Score game[5]={Score(98,67),Score(105,103),Score(88,96)};
game[3].Set(100,100);
game[4].Set(100,100);
query();
Score end;
result(game,end);
if(end.GetHometeam>end.GetOpponent) std::cout<<"Victor: HomeTeam"<<std::endl;
else std::cout<<"Victor: Opponent"<<std::endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询