Advertisement
Aaaaaarb

Untitled

Nov 11th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string>
  4. using namespace std;
  5. //Players Class
  6. class Player
  7. {
  8. private:
  9. // Variables
  10. int Id;
  11. string Name;
  12. string Nationality;
  13. int Number;
  14.  
  15. public:
  16. static int PlayerID;
  17. Player(){
  18. Id = PlayerID++;
  19. Name = "Default";
  20. Nationality = "Unknown";
  21. Number = 1;
  22.  
  23. }
  24. Player(string name, string nationality, int number)
  25. {
  26. Id = PlayerID++;
  27. Name = name;
  28. Nationality = Nationality;
  29. Number = 1;
  30. }
  31. //Destructer
  32. ~Player() {}
  33. int Run()
  34. {
  35. return rand() % 100;
  36. }
  37.  
  38. };
  39. //ID Reset
  40. int Player::PlayerID = 0;
  41.  
  42. //Teams Class
  43. class Team
  44. {
  45. private:
  46. // Variables
  47. int Id;
  48. string Name;
  49. int Ranking;
  50. int Points;
  51. //set of players
  52. Player* Players;
  53. public:
  54. static int TeamID;
  55. Team()
  56. {
  57. Id = TeamID++;
  58. Name = "Player";
  59. Ranking = 0;
  60. Points = 0;
  61. Players = NULL;
  62. }
  63. Team(string name, int ranking, int points, Player* players)
  64. {
  65. Id = TeamID++;
  66. Name = name;
  67. Ranking = ranking;
  68. Points = points;
  69. Players = players;
  70. }
  71. //Destructer
  72. ~Team() {}
  73. void RegisterPlayer(Player p)
  74. {
  75. *Players = p;
  76. }
  77. int returnPoints() {
  78. return Points;
  79. }
  80. };
  81. //ID Reset
  82. int Team::TeamID = 0;
  83.  
  84. //League Class
  85. class League
  86. {
  87. private:
  88. // Variables
  89. int Id;
  90. string Name;
  91. string Nationality;
  92. int Number;
  93. Team* Teams;
  94. public:
  95. static int LeagueID;
  96. League()
  97. {
  98. Id = LeagueID++;
  99. Name = "Player";
  100. Nationality = "Unknown";
  101. Number = 0;
  102. Teams = NULL;
  103. }
  104. League(string name, string nationality, int number, Team* teams)
  105. {
  106. Id = LeagueID++;
  107. Name = name;
  108. Nationality = nationality;
  109. Number = number;
  110. Teams = teams;
  111. }
  112. //Destructer
  113. ~League() {}
  114.  
  115. Team* GetTeams()
  116. {
  117. return Teams;
  118. }
  119. };
  120. //ID Reset
  121. int League::LeagueID = 0;
  122. /*Linked List *Failed attempt to sort teams and players*
  123. class node {
  124. public:
  125. int data;
  126. node* next;
  127. };
  128. class linked_list {
  129. private:
  130.  
  131. public:
  132. node* head, * tail;
  133. linked_list() {
  134. head = NULL;
  135. tail = NULL;
  136. }
  137. void add_node(int n)
  138. {
  139. node* tmp = new node;
  140. tmp->data = n;
  141. tmp->next = NULL;
  142.  
  143. if (head == NULL)
  144. {
  145. head = tmp;
  146. tail = tmp;
  147. }
  148. else
  149. {
  150. tail->next = tmp;
  151. tail = tail->next;
  152. }
  153. }
  154. };*/
  155.  
  156.  
  157. void main()
  158. {
  159. //Arrays sizes
  160. int sizeOfLeagues;
  161. int sizeOfTeam;
  162. int sizeOfPlayers;
  163. cout << "How many leagues do you want to create?" << endl;
  164. cin >> sizeOfLeagues;
  165. cout << "How many Teams in this league :" << endl;
  166. cin >> sizeOfTeam;
  167.  
  168. cout << "How many Players in this team :" << endl;
  169. cin >> sizeOfPlayers;
  170.  
  171. //Defining Variables
  172. League* ptrLeagues = new League[sizeOfLeagues];
  173. Player* ptrPlayers = new Player[sizeOfTeam];
  174. Team* ptrTeams = new Team[sizeOfPlayers];
  175.  
  176. string name;
  177. string teamName;
  178. string playerName;
  179. string nationality;
  180. string playerNationality;
  181.  
  182. int number;
  183. int playerNumber;
  184. int teamRank;
  185. int teamPoints;
  186.  
  187. //Start the magic
  188.  
  189. //Leagues Loop
  190. for (int i = 0; i < sizeOfLeagues; i++)
  191. {
  192. cout << "League name :" << endl;
  193. cin >> name;
  194. cout << "League nationailty :" << endl;
  195. cin >> nationality;
  196. cout << "League number :" << endl;
  197. cin >> number;
  198. //Teams Loop
  199. for (int j = 0; j < sizeOfTeam; j++)
  200. {
  201. cout << "Team name :" << endl;
  202. cin >> teamName;
  203. cout << "Team ranking :" << endl;
  204. cin >> teamRank;
  205. cout << "Team points :" << endl;
  206. cin >> teamPoints;
  207.  
  208. //Players Loop
  209.  
  210. for (int k = 0; k < sizeOfPlayers; k++)
  211. {
  212. cout << "Player name :" << endl;
  213. cin >> playerName;
  214. cout << "Player nationality :" << endl;
  215. cin >> playerNationality;
  216. cout << "Player number :" << endl;
  217. cin >> playerNumber;
  218. Player player(playerName, playerNationality, playerNumber);
  219.  
  220. *(ptrPlayers + k) = player;
  221. }
  222. Team team(teamName, teamRank, teamPoints, ptrPlayers);
  223.  
  224. *(ptrTeams + j) = team;
  225. }
  226. League League(name, nationality, number, ptrTeams);
  227.  
  228. *(ptrLeagues + i) = League;
  229. }
  230.  
  231.  
  232. system("pause");
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement