C++ code:- create at least the following classes in addition to other classes that are given to you: A sports associatio
Posted: Tue Jul 12, 2022 8:11 am
C++ code:-
create at least the following classes in addition to otherclasses that are given to you:
A sports association is going to contain an aggregate of sportsteams. In our workshop, there are two types ofsports teams - a hockey team anda baseball team.A hockey team will keep track of ateam's wins, losses, ties and willcalculate points based on these. A baseball teamwill keep track of a team's wins andlosses and will calculate a winning percentage basedon these (percentage in the context of baseball is a numberbetween 0.000 and 1.000).
The main sports association program will create one sportsassociation and add teams to it based on user input.
For this workshop, the main sports association program is givento you: SportsMain.cpp. The Team abstract base class is alsogiven to you as well as source code for creating ateam: Team.h and Team.cpp.
More details are given below:
The Team Abstract Class
The Team abstract class contains three functions (pure virtual)which will be completed in the derivedclasses:
Team.cpp contains a function to create a team based on userinput:
The Baseball Team
The baseball team completes the abstractclass and adds a constructor. The baseball team hasa name, the number of wins, the number of losses, andthe winning percentage:
The Hockey Team
The hockey team completes the abstract classand adds a constructor. The hockey team has a name,the number of wins, the number of ties, the number of losses, andthe total points:
The Sports Association
The sports association has a name and containsan aggregate of teams. These teams couldbe hockey teams, baseball teamsor both. We will limit the number of teams to 4. It has thefollowing functions:
//Team.h - class declarations for a team
#ifndef _TEAM_H_#define _TEAM_H_
#include <iostream>
enum Err_Status { Err_Success, Err_Undefined, Err_OutOfBounds, Err_Calculation};
class Team {public: virtual std::string GetName() const = 0; virtual Err_Status display() const = 0; virtual bool operator==(const Team&) const =0;};
Team* CreateTeam();
#endif// _TEAM_H_
//Team.cpp - Function for creating teams through the abstractinterface
#include <string>#include "BaseballTeam.h"#include "HockeyTeam.h"
using namespace std;
Team* CreateTeam() { Team* team = nullptr; int select = 0;
string name; int wins; int ties; int losses; do { cout << endl; cout << "Enter 1 for abaseball team, or" << endl; cout << "enter 2 for ahockey team." << endl; cin >> select; cin.ignore(1000, '\n');
switch (select) { case 1: cout<< "What's the team's name? "; getline(cin, name); cout<< "Enter the number of wins: "; cin>> wins; cout<< "Enter the number of losses: "; cin>> losses; team = newBaseballTeam(name, wins, losses); break; case 2: cout<< "What's the team's name? "; getline(cin, name); cout<< "Enter the number of wins: "; cin>> wins; cout<< "Enter the number of ties: "; cin>> ties; cout<< "Enter the number of losses: "; cin>> losses; team = newHockeyTeam(name, wins, ties, losses); break; } } while (select < 1 || select>2);
return team;}
//SportsMain.cpp - main function for the sports association
#include "SportsAssociation.h"#include "BaseballTeam.h"#include "HockeyTeam.h"
using namespace std;
int main() { SportsAssociation assoc("Rexdale SportsAssociation");
for (int i = 0; i < MAX; ++i) { Team* team =CreateTeam(); assoc += *team; } assoc.display();
return 0;}
create at least the following classes in addition to otherclasses that are given to you:
A sports association is going to contain an aggregate of sportsteams. In our workshop, there are two types ofsports teams - a hockey team anda baseball team.A hockey team will keep track of ateam's wins, losses, ties and willcalculate points based on these. A baseball teamwill keep track of a team's wins andlosses and will calculate a winning percentage basedon these (percentage in the context of baseball is a numberbetween 0.000 and 1.000).
The main sports association program will create one sportsassociation and add teams to it based on user input.
For this workshop, the main sports association program is givento you: SportsMain.cpp. The Team abstract base class is alsogiven to you as well as source code for creating ateam: Team.h and Team.cpp.
More details are given below:
The Team Abstract Class
The Team abstract class contains three functions (pure virtual)which will be completed in the derivedclasses:
Team.cpp contains a function to create a team based on userinput:
The Baseball Team
The baseball team completes the abstractclass and adds a constructor. The baseball team hasa name, the number of wins, the number of losses, andthe winning percentage:
The Hockey Team
The hockey team completes the abstract classand adds a constructor. The hockey team has a name,the number of wins, the number of ties, the number of losses, andthe total points:
The Sports Association
The sports association has a name and containsan aggregate of teams. These teams couldbe hockey teams, baseball teamsor both. We will limit the number of teams to 4. It has thefollowing functions:
//Team.h - class declarations for a team
#ifndef _TEAM_H_#define _TEAM_H_
#include <iostream>
enum Err_Status { Err_Success, Err_Undefined, Err_OutOfBounds, Err_Calculation};
class Team {public: virtual std::string GetName() const = 0; virtual Err_Status display() const = 0; virtual bool operator==(const Team&) const =0;};
Team* CreateTeam();
#endif// _TEAM_H_
//Team.cpp - Function for creating teams through the abstractinterface
#include <string>#include "BaseballTeam.h"#include "HockeyTeam.h"
using namespace std;
Team* CreateTeam() { Team* team = nullptr; int select = 0;
string name; int wins; int ties; int losses; do { cout << endl; cout << "Enter 1 for abaseball team, or" << endl; cout << "enter 2 for ahockey team." << endl; cin >> select; cin.ignore(1000, '\n');
switch (select) { case 1: cout<< "What's the team's name? "; getline(cin, name); cout<< "Enter the number of wins: "; cin>> wins; cout<< "Enter the number of losses: "; cin>> losses; team = newBaseballTeam(name, wins, losses); break; case 2: cout<< "What's the team's name? "; getline(cin, name); cout<< "Enter the number of wins: "; cin>> wins; cout<< "Enter the number of ties: "; cin>> ties; cout<< "Enter the number of losses: "; cin>> losses; team = newHockeyTeam(name, wins, ties, losses); break; } } while (select < 1 || select>2);
return team;}
//SportsMain.cpp - main function for the sports association
#include "SportsAssociation.h"#include "BaseballTeam.h"#include "HockeyTeam.h"
using namespace std;
int main() { SportsAssociation assoc("Rexdale SportsAssociation");
for (int i = 0; i < MAX; ++i) { Team* team =CreateTeam(); assoc += *team; } assoc.display();
return 0;}