Advertisement
Guest User

Untitled

a guest
Dec 8th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.10 KB | None | 0 0
  1. /*
  2. CH08-320142
  3. TournamentMember.cpp
  4. Taiyr Begeyev
  5. t.begeyev@jacobs-university.de
  6. */
  7.  
  8. #include "TournamentMember.h"
  9. #include <iostream>
  10. #include <cstring>
  11.  
  12. using namespace std;
  13.  
  14. string TournamentMember::location = "Germany";
  15. //default constructor
  16. TournamentMember::TournamentMember()
  17. {
  18. cout << "default constructor of TournamentMember class being called" << endl;
  19. strcpy(first_name, "Admin");
  20. strcpy(last_name, "Password");
  21. strcpy(date_of_birth, "1970-01-01");
  22. strcpy(email, "google@gmail.com");
  23. strcpy(phone_number, "+66666666666");
  24. }
  25.  
  26. //constructor
  27. TournamentMember::TournamentMember(char* first_name, char* last_name,
  28. char* date_of_birth, char* email, char* phone_number)
  29. {
  30. cout << "constructor of TournamentMember class being called" << endl;
  31.  
  32. strcpy(this->first_name, first_name);
  33. strcpy(this->last_name, last_name);
  34. strcpy(this->date_of_birth, date_of_birth);
  35. strcpy(this->email, email);
  36. strcpy(this->phone_number, phone_number);
  37. }
  38.  
  39. //copy constructor
  40. TournamentMember::TournamentMember(const TournamentMember& src)
  41. {
  42. cout << "copy constructor of TournamentMember class being called" << endl;
  43. strcpy(first_name, src.first_name);
  44. strcpy(last_name, src.last_name);
  45. strcpy(date_of_birth, src.date_of_birth);
  46. strcpy(email, src.email);
  47. strcpy(phone_number, src.phone_number);
  48. }
  49.  
  50. //destructor
  51. TournamentMember::~TournamentMember()
  52. {
  53. cout << "destructor of TournamentMember class being called" << endl;
  54. }
  55.  
  56.  
  57. //service method
  58. void TournamentMember::print()
  59. {
  60. cout << "First name: " << first_name << endl;
  61. cout << "Last name: " << last_name << endl;
  62. cout << "Date of birth: " << date_of_birth << endl;
  63. cout << "Location: " << location << endl;
  64. cout << "Email: " << email << endl;
  65. cout << "Phone number: " << phone_number << endl;
  66. }
  67.  
  68. //method for changing Location
  69. void TournamentMember::set_location(string newlocation)
  70. {
  71. location = newlocation;
  72. }
  73.  
  74. /*
  75. Player
  76. */
  77. //constructor
  78. Player::Player(char* first_name, char* last_name, char* date_of_birth,
  79. char* email, char* phone_number, int number,
  80. string position, int goals, string _footed)
  81. : TournamentMember(first_name, last_name, date_of_birth,
  82. email, phone_number)
  83. {
  84. cout << "constructor of Player class being called" << endl;
  85. this->number = number;
  86. this->position = position;
  87. this->goals = goals;
  88. this->_footed = _footed;
  89. }
  90.  
  91. //copy constructor
  92. Player::Player(const Player& src): TournamentMember(src)
  93. {
  94. cout << "copy constructor of Player class being called" << endl;
  95. number = src.number;
  96. position = src.position;
  97. goals = src.goals;
  98. _footed = src._footed;
  99. }
  100.  
  101. //destructor
  102. Player::~Player()
  103. {
  104. cout << "destructor of Player class being called" << endl;
  105. }
  106.  
  107. //service methods
  108. void Player::print()
  109. {
  110. TournamentMember::print();
  111. cout << "Number: " << number << endl;
  112. cout << "Position: " << position << endl;
  113. cout << "Goals: " << goals << endl;
  114. cout << "Foot: " << _footed << endl;
  115. cout << endl;
  116. }
  117.  
  118. void Player::increment_goals(int add_goals)
  119. {
  120. goals = goals + add_goals;
  121. }
  122.  
  123. /*
  124. CH08-320142
  125. TournamentMember.h
  126. Taiyr Begeyev
  127. t.begeyev@jacobs-university.de
  128. */
  129.  
  130. #include <iostream>
  131. #include <cstring>
  132. #ifndef TOURNAMENTMEMBER_H
  133. #define TOURNAMENTMEMBER_H
  134.  
  135. class TournamentMember
  136. {
  137. private:
  138. char first_name[36];
  139. char last_name[36];
  140. char date_of_birth[11];
  141. char email[50];
  142. char phone_number[50];
  143. public:
  144. static std::string location;
  145. //empty constructor
  146. TournamentMember();
  147. //parametric constructor
  148. TournamentMember(char*, char*, char*, char*, char*);
  149. //copy constructor
  150. TournamentMember(const TournamentMember&);
  151. //destructor
  152. ~TournamentMember();
  153.  
  154. //setter methods
  155. void set_first_name(char*);
  156. void set_last_name(char*);
  157. void set_date_of_birth(char*);
  158. void set_email(char*);
  159. void set_phone_number(char*);
  160.  
  161. //getter methods
  162. char* get_first_name();
  163. char* get_last_name();
  164. char* get_date_of_birth();
  165. std::string get_location();
  166. char* get_email();
  167. char* get_phone_number();
  168.  
  169. //service methods
  170. void print();
  171. //method for changing location
  172. static void set_location(std::string);
  173. };
  174.  
  175.  
  176. class Player : public TournamentMember
  177. {
  178. private:
  179. int number;
  180. std::string position;
  181. std::string _footed;
  182. int goals;
  183. public:
  184. //constructor
  185. Player(char*, char*, char*, char*, char*, int, std::string, int, std::string);
  186. //copy constructor
  187. Player(const Player&);
  188. //destructor
  189. ~Player();
  190.  
  191. //setter methods
  192. void set_number(int);
  193. void set_position(std::string);
  194. void set_footed(std::string);
  195.  
  196. //getter methods
  197. int get_number();
  198. std::string get_position();
  199. std::string get_footed();
  200. int get_goals();
  201.  
  202. //service method
  203. void print();
  204. void increment_goals(int);
  205. };
  206.  
  207.  
  208. //inline setter methods
  209. inline void TournamentMember::set_first_name(char* first_name)
  210. {
  211. strcpy(this->first_name, first_name);
  212. }
  213.  
  214. inline void TournamentMember::set_last_name(char* last_name)
  215. {
  216. strcpy(this->last_name, last_name);
  217. }
  218.  
  219. inline void TournamentMember::set_date_of_birth(char* date_of_birth)
  220. {
  221. strcpy(this->date_of_birth, date_of_birth);
  222. }
  223.  
  224. inline void TournamentMember::set_email(char* email)
  225. {
  226. strcpy(this->email, email);
  227. }
  228.  
  229. inline void TournamentMember::set_phone_number(char* phone_number)
  230. {
  231. strcpy(this->phone_number, phone_number);
  232. }
  233.  
  234. //inline getter methods
  235. inline char* TournamentMember::get_first_name()
  236. {
  237. return first_name;
  238. }
  239.  
  240. inline char* TournamentMember::get_last_name()
  241. {
  242. return last_name;
  243. }
  244.  
  245. inline char* TournamentMember::get_date_of_birth()
  246. {
  247. return date_of_birth;
  248. }
  249.  
  250. inline std::string TournamentMember::get_location()
  251. {
  252. return location;
  253. }
  254.  
  255. inline char* TournamentMember::get_email()
  256. {
  257. return email;
  258. }
  259.  
  260. inline char* TournamentMember::get_phone_number()
  261. {
  262. return phone_number;
  263. }
  264.  
  265.  
  266. /*
  267. Player class
  268. */
  269.  
  270. //setter methods
  271. inline void Player::set_number(int number)
  272. {
  273. this->number = number;
  274. }
  275.  
  276. inline void Player::set_position(std::string position)
  277. {
  278. this->position = position;
  279. }
  280.  
  281. inline void Player::set_footed(std::string _footed)
  282. {
  283. this->_footed = _footed;
  284. }
  285.  
  286. //getter methods
  287. inline int Player::get_number()
  288. {
  289. return number;
  290. }
  291.  
  292. inline std::string Player::get_position()
  293. {
  294. return position;
  295. }
  296.  
  297. inline std::string Player::get_footed()
  298. {
  299. return _footed;
  300. }
  301.  
  302. inline int Player::get_goals()
  303. {
  304. return goals;
  305. }
  306.  
  307.  
  308. #endif
  309.  
  310. /*
  311. CH08-320142
  312. testPlayer.cpp
  313. Taiyr Begeyev
  314. t.begeyev@jacobs-university.de
  315. */
  316.  
  317. #include "TournamentMember.h"
  318. #include <iostream>
  319.  
  320. using namespace std;
  321.  
  322. int main()
  323. {
  324. char first_name_1[] = "Lionel";
  325. char last_name_1[] = "Messi";
  326. char date_of_birth_1[] = "1987-06-24";
  327. char email_1[] = "messi@barcelona.org";
  328. char phone_number_1[] = "+123456789";
  329. int number_1 = 10;
  330. string position_1 = "Forward";
  331. int goals_1 = 12;
  332. string foot_1 = "left-footed";
  333.  
  334. char first_name_2[] = "Luis";
  335. char last_name_2[] = "Suarez";
  336. char date_of_birth_2[] = "1987-01-24";
  337. char email_2[] = "suarez@barcelona.org";
  338. char phone_number_2[] = "+123456780";
  339. int number_2 = 9;
  340. string position_2 = "Forward";
  341. int goals_2 = 8;
  342. string foot_2 = "rigth-footed";
  343.  
  344. char first_name_3[] = "Philippe";
  345. char last_name_3[] = "Coutinho";
  346. char date_of_birth_3[] = "1992-06-12";
  347. char email_3[] = "coutinho@barcelona.org";
  348. char phone_number_3[] = "+123456781";
  349. int number_3 = 14;
  350. string position_3 = "Forward";
  351. int goals_3 = 6;
  352. string foot_3 = "rigth-footed";
  353.  
  354. //creating instances of class
  355. Player tournamentmember_1(first_name_1, last_name_1, date_of_birth_1,
  356. email_1, phone_number_1, number_1, position_1,
  357. goals_1,foot_1);
  358. Player tournamentmember_2(first_name_2, last_name_2, date_of_birth_2,
  359. email_2, phone_number_2, number_2, position_2,
  360. goals_2, foot_2);
  361. Player tournamentmember_3(first_name_3, last_name_3, date_of_birth_3,
  362. email_3, phone_number_3, number_3, position_3,
  363. goals_3, foot_3);
  364. Player tournamentmember_4(tournamentmember_3);
  365.  
  366. //checking method
  367. tournamentmember_1.increment_goals(3);
  368. tournamentmember_2.increment_goals(1);
  369. tournamentmember_3.increment_goals(1);
  370.  
  371. //moving everyone to Hamburg :c
  372. tournamentmember_1.set_location("Hamburg");
  373. tournamentmember_2.set_location("Hamburg");
  374. tournamentmember_3.set_location("Hamburg");
  375.  
  376. //printing everything
  377. tournamentmember_1.print();
  378. tournamentmember_2.print();
  379. tournamentmember_3.print();
  380.  
  381. return 0;
  382. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement