Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "TournamentMember.h"
  4.  
  5. /* ----- TournamentMember Class ----- */
  6. std::string TournamentMember::location = "Default Location";
  7.  
  8. // Parametric constructor with all parameters
  9. TournamentMember::TournamentMember(char const *firstN, char const *lastN,
  10.                                    char const *dOB, std::string &Location,
  11.                                    std::string Role, bool Active) {
  12.     std::cout << "TournamentMember Parametric Constructor!\n";
  13.     (*this).firstName = firstN;
  14.     (*this).lastName = lastN;
  15.     (*this).dateOfBirth = dOB;
  16.     (*this).updateLocation(Location);
  17.     (*this).role = Role;
  18.     (*this).active = Active;
  19. }
  20.  
  21. // Default Constructor
  22. TournamentMember::TournamentMember() {
  23.     std::cout << "TournamentMember Default Constructor!\n";
  24.     (*this).firstName = "Default";
  25.     (*this).lastName = "Default";
  26.     (*this).dateOfBirth = "0000-00-00";
  27.     (*this).role = "Participant";
  28.     (*this).active = true;
  29. }
  30.  
  31. // Copy constructor
  32. TournamentMember::TournamentMember(const TournamentMember& obj) {
  33.     std::cout << "TournamentMember Copy Constructor!\n";
  34.     (*this).firstName = obj.firstName;
  35.     (*this).lastName = obj.lastName;
  36.     (*this).dateOfBirth = obj.dateOfBirth;
  37.     (*this).updateLocation(obj.location);
  38.     (*this).role = obj.role;
  39.     (*this).active = obj.active;
  40. }
  41.  
  42. // Destructor
  43. TournamentMember::~TournamentMember() {
  44.     std::cout << "Destructor!\n";
  45. }
  46.  
  47. // Setter methods for each data member
  48. inline void TournamentMember::setFirstName(char const *FirstName) {
  49.     firstName = FirstName;
  50. }
  51.  
  52. inline void TournamentMember::setLastName(char const *LastName) {
  53.     lastName = LastName;
  54. }
  55.  
  56. inline void TournamentMember::setDateOfBirth(char const *DateOfBirth) {
  57.     dateOfBirth = DateOfBirth;
  58. }
  59.  
  60. inline void TournamentMember::setRole(std::string Role) {
  61.     role = Role;
  62. }
  63.  
  64. inline void TournamentMember::setActive(bool Active) {
  65.     active = Active;
  66. }
  67.  
  68. // Getter methods for each data members
  69. inline char const* TournamentMember::getFirstName() const {
  70.     return firstName;
  71. }
  72.  
  73. inline char const* TournamentMember::getLastName() const {
  74.     return lastName;
  75. }
  76.  
  77. inline char const* TournamentMember::getDateOfBirth() const {
  78.     return dateOfBirth;
  79. }
  80.  
  81. inline std::string TournamentMember::getLocation() const {
  82.     return location;
  83. }
  84.  
  85. inline std::string TournamentMember::getRole() const {
  86.     return role;
  87. }
  88.  
  89. inline bool TournamentMember::getActive() const {
  90.     return active;
  91. }
  92.  
  93. // Methods
  94. // Method to output to stdout all data member of the instance formatted
  95. void TournamentMember::printInformation() {
  96.     std::cout << "First Name: "
  97.               << getFirstName()
  98.               << "\nLast Name: "
  99.               << getLastName()
  100.               << "\nDate of Birth: "
  101.               << getDateOfBirth()
  102.               << "\nLocation: "
  103.               << getLocation()
  104.               << "\nRole: "
  105.               << getRole()
  106.               << "\nActive: "
  107.               << getActive()
  108.               << std::endl;
  109. }
  110.  
  111. // Method to change the static location data member
  112. void TournamentMember::updateLocation(const std::string& updatedLocation) {
  113.     std::cout << "Updating tournament location to "
  114.               << updatedLocation
  115.               << std::endl;
  116.     location = updatedLocation;
  117. }
  118. /* ---------------------------------- */
  119.  
  120. /* ----- Player Class --------------- */
  121. // Parametric constructor with all parameters
  122. Player::Player(char const *firstN, char const *lastN, char const *dOB,
  123.                std::string &Location, std::string Role, bool Active, int Number,
  124.                std::string Position, int GoalsScored, std::string DominantFoot)
  125.                : TournamentMember(firstN, lastN, dOB, Location, "Player",
  126.                                   Active) {
  127.     std::cout << "Player Parametric Constructor!\n";
  128.     (*this).number = Number;
  129.     (*this).position = Position;
  130.     (*this).goalsScored = GoalsScored;
  131.     (*this).dominantFoot = DominantFoot;
  132. }
  133.  
  134. // Default constructor
  135. Player::Player() : TournamentMember() {
  136.     std::cout << "Player Default Constructor!\n";
  137.     (*this).setRole("Player");
  138.     (*this).number = 0;
  139.     (*this).position = "Default Position";
  140.     (*this).goalsScored = 0;
  141.     (*this).dominantFoot = "Neither";
  142. }
  143.  
  144. // Copy constructor
  145. Player::Player(const Player& obj) : TournamentMember(obj) {
  146.     std::cout << "Player Copy Constructor!\n";
  147.     (*this).number = obj.number;
  148.     (*this).position = obj.position;
  149.     (*this).goalsScored = obj.goalsScored;
  150.     (*this).dominantFoot = obj.dominantFoot;
  151. }
  152.  
  153. // Destructor
  154. Player::~Player() {
  155.     std::cout << "Player Destructor!\n";
  156. }
  157.  
  158. // Setter methods
  159. inline void Player::setNumber(int Number) {
  160.     number = Number;
  161. }
  162.  
  163. inline void Player::setPosition(std::string Position) {
  164.     position = Position;
  165. }
  166.  
  167. inline void Player::setDominantFoot(std::string DominantFoot) {
  168.     dominantFoot = DominantFoot;
  169. }
  170.  
  171. // Getter methods
  172. inline int Player::getNumber() const {
  173.     return (*this).number;
  174. }
  175.  
  176. inline std::string Player::getPosition() const {
  177.     return (*this).position;
  178. }
  179.  
  180. inline int Player::getGoalsScored() const {
  181.     return (*this).goalsScored;
  182. }
  183.  
  184. inline std::string Player::getDominantFoot() const {
  185.     return (*this).dominantFoot;
  186. }
  187.  
  188. // Methods
  189. // Method to output to stdout all data member of the instance Player formatted
  190. void Player::printPlayerInformation() const {
  191.     std::cout << "Number: "
  192.               << getNumber()
  193.               << "\nPosition: "
  194.               << getPosition()
  195.               << "\nGoals Scored: "
  196.               << getGoalsScored()
  197.               << "\nDominant Foot: "
  198.               << getDominantFoot()
  199.               << std::endl;
  200. }
  201.  
  202. // Method to increment by 1 the data member goalsScored of Player instance
  203. void Player::incrementGoalsScored() {
  204.     int score = getGoalsScored();
  205.     score++;
  206.     (*this).goalsScored = score;
  207. }
  208. /* ---------------------------------- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement