Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. #include <string>
  5. #include <sstream>
  6. #include <fstream>
  7. using namespace std;
  8. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  9. class Player{
  10.  
  11. private:
  12. string firstName;
  13. string lastName;
  14. int height;
  15. vector<string>skills;
  16.  
  17. public:
  18. static vector<Player*> PlayersAll;
  19.  
  20. Player(string fn, string ln, int h){
  21. firstName = fn;
  22. lastName = ln;
  23. height = h;
  24. skills.push_back("Shooting");
  25. skills.push_back("Passing");
  26. skills.push_back("Dribbling");
  27. skills.push_back("Defence");
  28. skills.push_back("Heading");
  29.  
  30. PlayersAll.push_back(this);
  31. }
  32.  
  33. Player(const Player &p){
  34. firstName = p.firstName;
  35. lastName = p.lastName;
  36. height = p.height;
  37. skills = p.skills;
  38. }
  39.  
  40. string GetFirstName(){
  41. return firstName;
  42. }
  43. string GetLastName(){
  44. return lastName;
  45. }
  46. void changeFirstName(string s){
  47. firstName = s;
  48. }
  49. void changeLastName(string s){
  50. lastName = s;
  51. }
  52. void changeHeight(int i){
  53. height = i;
  54. }
  55.  
  56. void AddSkill(string s){
  57. skills.push_back(s);
  58. }
  59. string showInfo(){
  60. ostringstream ss;
  61. ss << height;
  62. string skillsToReturn = "\n";
  63. for(int i =0;i<skills.size();i++){
  64. skillsToReturn+= skills[i]+"\n";
  65. }
  66. return "My name is: " + firstName + " " + lastName + "\nHeight: " + ss.str() +"\nSkills: "+skillsToReturn;
  67.  
  68. }
  69. };
  70. vector<Player*> Player::PlayersAll; //????????????
  71.  
  72.  
  73.  
  74. class Team{
  75. static int maxPlayersInTeam;
  76. static int teamsAlreadyCreated;
  77. string teamName;
  78.  
  79. public:
  80. vector<Player*> playersInTeam;
  81. Team(string tn){
  82. teamName = tn;
  83.  
  84. for(int i = (teamsAlreadyCreated*5);i<maxPlayersInTeam+(5*teamsAlreadyCreated);i++){
  85. playersInTeam.push_back(Player::PlayersAll[i]);
  86. }
  87. teamsAlreadyCreated++;
  88. }
  89. Team(string tn, ifstream& f){
  90. teamName = tn;
  91. vector<int> semicolonPositions;
  92. string line;
  93. while(getline(f,line)){
  94. for(int i=0;i<line.length();i++){
  95. if(line[i]==';'){
  96. semicolonPositions.push_back(i);
  97. }
  98. }
  99. int height;
  100. istringstream iss(line.substr(semicolonPositions[1]+1));
  101. iss >> height;
  102. Player *p = new Player(line.substr(0, semicolonPositions[0]),line.substr(semicolonPositions[0]+1,semicolonPositions[1]-semicolonPositions[0]-1), height);
  103. playersInTeam.push_back(p);
  104. string firstName = line.substr(0, semicolonPositions[0]);
  105. string lastName = line.substr(semicolonPositions[0]+1,semicolonPositions[1]-semicolonPositions[0]-1);
  106. string height2 = line.substr(semicolonPositions[1]+1);
  107. // cout << "First Name: " << firstName << endl;
  108. // cout << "Last Name: " << lastName << endl;
  109. // cout << "Height: " << height2 << endl;
  110. cout << "\n\n";
  111. semicolonPositions.clear();
  112. }
  113.  
  114. }
  115.  
  116. Team(const Team &t){
  117. teamName = t.teamName;
  118. playersInTeam = t.playersInTeam;
  119. }
  120. void changeTeamName(string tn){
  121. teamName = tn;
  122. }
  123.  
  124. string TeamInfo(){
  125. string stringToReturn;
  126. stringToReturn += "\n\nOur name is: "+ teamName + "! \nOur players: ";
  127. for(int i = 0; i<playersInTeam.size();i++){
  128. stringToReturn+="\n" +playersInTeam[i] -> GetFirstName()+" " +playersInTeam[i] ->GetLastName();
  129. //stringToReturn+="\n" +playersInTeam[i].GetFirstName()+" " +playersInTeam[i].GetLastName();
  130. }
  131. return stringToReturn;
  132. }
  133. };
  134. int Team::maxPlayersInTeam = 5;
  135. int Team::teamsAlreadyCreated = 0;////????????????????????//////////////
  136.  
  137. int main(int argc, char** argv) {
  138. //Player* p2 = &p1;
  139. // cout << p2 << endl;
  140. //cout << &p1 << endl;
  141. // cout << (*p2).GetFirstName() << endl;
  142. //cout << p1 << endl;
  143.  
  144. /* Player p1("A", "A", 181);
  145. cout << p1.showInfo();
  146. Player p2("B", "B", 131);
  147. Player p3("C", "C", 151);
  148. Player p4("D", "D", 131);
  149. Player p5("F", "F", 131);
  150. Player p6("G", "G", 181);
  151. Player p7("H", "H", 131);
  152. Player p8("J", "J", 151);
  153. Player p9("K", "K", 131);
  154. Player p10("L", "L", 131);
  155. Team t1("T1");
  156. Team t2("T2");
  157. Team t3 = t2;
  158. t3.changeTeamName("T3");
  159. cout << t1.TeamInfo();
  160. cout << "\n" << endl;
  161. cout << t2.TeamInfo();
  162. cout << "\n" << endl;
  163. cout << t3.TeamInfo() << endl;
  164.  
  165. cout << "------------" << endl;
  166. p10.changeFirstName("DDDD");
  167. cout << t1.TeamInfo();
  168. cout << "\n" << endl;
  169. cout << t2.TeamInfo();
  170. cout << "\n" << endl;
  171. cout << t3.TeamInfo();*/
  172. // Player p("a","b",120);
  173. ifstream f("example.txt");
  174. Team t1("T1",f);
  175. cout << Player::PlayersAll.size();
  176. cout << Player::PlayersAll[0] -> showInfo();
  177. cout << t1.TeamInfo();
  178.  
  179.  
  180. return 0;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement