Apr 7, 2016 at 3:09pm UTC
I am currently doing an assignment that utilizes classes to create a basic score board, this is what I have at the moment:
class Team
{
private:
string Name="setName\n";
string Coach_Name="setName\n";
string Home_City="setName\n";
int Team_Fouls;
int Score;
double Timeout_Count;
bool Home_Status;
public:
void setName (string &);
void setCoach_Name(string &);
void setHome_City(string &);
void setScore(int);
void setTeam_Fouls(int);
void setTimeout_Count(double);
void setHome_Status(bool);
string getName();
string getCoach_Name();
string getHome_City();
int getScore() ;
int getTeam_Fouls();
double getTimeout_Count() ;
bool getHome_Status() ;
};
void Team::setName(string &N)
{
Name = N;
}
void Team::setCoach_Name(string &C)
{
Coach_Name = C;
}
void Team::setHome_City(string &H)
{
Home_City = H;
}
void Team::setScore(int s)
{
Score = s;
}
void Team::setTeam_Fouls(int f)
{
Team_Fouls = f;
}
void Team::setHome_Status(bool b)
{
Home_Status = b;
}
string Team::getName()
{
return Name;
}
string Team::getCoach_Name()
{
return Coach_Name;
}
string Team::getHome_City()
{
return Home_City;
}
double Team::getTimeout_Count()
{
return Timeout_Count;
}
int Team::getScore()
{
return Score;
}
int Team::getTeam_Fouls()
{
return Team_Fouls;
}
bool Team::getHome_Status()
{
return Home_Status;
}
class Scoreboard
{
private:
int Period;
int Home_Score;
int Visitor_Score;
int Player;
int Player_Fouls;
int Home_Fouls;
int Visitor_Fouls;
double Time;
bool Pos;
public:
void setPeriod(int);
void setHome_Score(int);
void setVisitor_Score(int);
void setPlayer(int);
void setPlayer_Fouls(int);
void setHome_Fouls(int);
void setVisitor_Fouls(int);
void setTime(double);
void setPos(bool);
int getPeriod();
int getHome_Score();
int getVisitor_Score();
int getPlayer();
int getPlayer_Fouls();
int getHome_Fouls();
int getVisitor_Fouls();
double getTime();
bool getPos();
};
void Scoreboard::setPeriod(int p)
{
Period = p;
}
void Scoreboard::setHome_Score(int hs)
{
Home_Score = hs;
}
void Scoreboard::setVisitor_Score(int vs)
{
Visitor_Score = vs;
}
void Scoreboard::setPlayer(int pn)
{
Player = pn;
}
void Scoreboard::setPlayer_Fouls(int pf)
{
Player_Fouls = pf;
}
void Scoreboard::setHome_Fouls(int hf)
{
Home_Fouls = hf;
}
void Scoreboard::setVisitor_Fouls(int vf)
{
Visitor_Fouls = vf;
}
void Scoreboard::setTime(double t)
{
Time = t;
}
void Scoreboard::setPos(bool P)
{
Pos = P;
}
int Scoreboard::getPeriod()
{
return Period;
}
int Scoreboard::getHome_Score()
{
return Home_Score;
}
int Scoreboard::getVisitor_Score()
{
return Visitor_Score;
}
int Scoreboard::getPlayer()
{
return Player;
}
int Scoreboard::getPlayer_Fouls()
{
return Player_Fouls;
}
int Scoreboard::getHome_Fouls()
{
return Home_Fouls;
}
int Scoreboard::getVisitor_Fouls()
{
return Visitor_Fouls;
}
double Scoreboard::getTime()
{
return Time;
}
bool Scoreboard::getPos()
{
return Pos;
}
Team team1;
Team team2;
Scoreboard scoreboardmain;
void displayScoreboard();
int main()
{
char decision = {0};
string input = " ";
int num = 0;
int posDecision = 0;
do
{
displayScoreboard();
changeColor(12);
cout << "\t\t\t\t\tMenu Switchboard" << endl;
changeColor(7);
changeColor(13);
cout << "\t\t\t\t\tA. Add/Edit Home Name" << endl;
cout << "\t\t\t\t\tB. Add/Edit Visitor Name" << endl;
cout << "\t\t\t\t\tC. Add/Edit Home Score" << endl;
cout << "\t\t\t\t\tD. Add/Edit Visitor Score" << endl;
cout << "\t\t\t\t\tE. Add/Edit Position" << endl;
cout << "\t\t\t\t\tX to Exit" << endl;
changeColor(7);
changeColor(12);
cout << "\t\t\t\t\tSelect an option: ";
changeColor(7);
cin >> decision;
if(decision == 'a' || decision == 'A')
{
cout << "What is the Home Name?: ";
input = validateString(input);
team1.setName(input);
}
if(decision == 'b' || decision == 'B')
{
cout << "What is the Visitor Name?: ";
input = validateString(input);
team2.setName(input);
}
if(decision == 'c' || decision == 'C')
{
cout << "What is the Home Score?: ";
num = validateInt(num);
team1.setScore(num);
}
if(decision == 'd' || decision == 'D')
{
cout << "What is the Visitor Score?: ";
num = validateInt(num);
team2.setScore(num);
}
if(decision == 'e' || decision == 'E')
{
cout << "1 = Home Possesion, 2 = Visitor Possesion: ";
posDecision = validateInt(posDecision);
if(posDecision == 1)
{
scoreboardmain.setPos(true);
}
else if(posDecision == 2)
{
scoreboardmain.setPos(false);
}
}
}while(decision != 'x' && decision !='X');
return 0;
}
void displayScoreboard()
{
system("cls");
changeColor(10);
cout<< "\t\tTeam1:\n\n " << team1.getName() << endl;
changeColor(7);
changeColor(9);
cout<< "\t\tTeam2:\n\n " << team2.getName() << endl;
changeColor(7);
changeColor(10);
cout<< "\t\tTeam1 Score: \n\n " << team1.getScore() << endl;
changeColor(7);
changeColor(9);
cout<< "\t\tTeam2 Score: \n\n " << team2.getScore() << endl;
changeColor(7);
cout<< "\t\tHome Possession: \n\n " << scoreboardmain.getPos() << endl;
cout<< "\t\tVisitor Possession: \n\n " << scoreboardmain.getPos() << endl;
}
void changeColor(int colorValue)//function with no return type, 1 parameter
{
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); //use of SetConsoleText
SetConsoleTextAttribute(console,colorValue); //set the color of text to
}
My problem is that on the home and visitor possession, whenever i type in '1' for home, it gives a '1' value to both visitor and home and whenever i type in '2', it zeroes out the possessions. What am i doing wrong??? Its using the 'bool' datatype by the way.