SHARE
TWEET

Untitled

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