masterm1nd99

dsakjm

Apr 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. class NBAPlayer{
  6. protected:
  7. char *ime;
  8. char tim[40];
  9. double poeni;
  10. double asistencii;
  11. double skokovi;
  12.  
  13. public:
  14. NBAPlayer(){}
  15. NBAPlayer(const char *ime, const char *tim, double poeni, double asistencii, double skokovi){
  16. this->ime = new char[strlen(ime)+1];
  17. strcpy(this->ime, ime);
  18. strcpy(this->tim, tim);
  19. this->poeni = poeni;
  20. this->asistencii = asistencii;
  21. this->skokovi = skokovi;
  22. }
  23.  
  24. NBAPlayer(const NBAPlayer &rhs){
  25. this->ime = new char[strlen(rhs.ime)+1];
  26. strcpy(this->ime, rhs.ime);
  27. strcpy(this->tim, rhs.tim);
  28. this->poeni = rhs.poeni;
  29. this->asistencii = rhs.asistencii;
  30. this->skokovi = rhs.skokovi;
  31. }
  32.  
  33. NBAPlayer &operator=(const NBAPlayer &rhs){
  34. this->ime = new char[strlen(rhs.ime)+1];
  35. strcpy(this->ime, rhs.ime);
  36. strcpy(this->tim, rhs.tim);
  37. this->poeni = rhs.poeni;
  38. this->asistencii = rhs.asistencii;
  39. this->skokovi = rhs.skokovi;
  40. return *this;
  41. }
  42.  
  43. double rating(){
  44. return poeni*0.45+asistencii*0.3+skokovi*0.25;
  45. }
  46.  
  47. void print(){
  48. cout << ime << " - " << tim << endl;
  49. cout << "Points: " << poeni << endl;
  50. cout << "Assists: " << asistencii << endl;
  51. cout << "Rebounds: " << skokovi << endl;
  52. cout << "Rating: " << rating() << endl;
  53. }
  54. };
  55.  
  56. class AllStarPlayer: public NBAPlayer{
  57. private:
  58. double poeni;
  59. double asistencii;
  60. double skokovi;
  61.  
  62. public:
  63. AllStarPlayer(){}
  64.  
  65. AllStarPlayer(const char *ime, const char *tim, double poeni, double asistencii, double skokovi
  66. , double AllStarPoeni, double AllStarAsistencii, double AllStarSkokovi): NBAPlayer(ime, tim, poeni, asistencii, skokovi){
  67. this->poeni = AllStarPoeni;
  68. this->asistencii = AllStarAsistencii;
  69. this->skokovi = AllStarSkokovi;
  70. }
  71.  
  72. AllStarPlayer(NBAPlayer &rhs, double AllStarPoeni, double AllStarAsistencii, double AllStarSkokovi): NBAPlayer(rhs){
  73. this->poeni = AllStarPoeni;
  74. this->asistencii = AllStarAsistencii;
  75. this->skokovi = AllStarSkokovi;
  76. }
  77.  
  78. AllStarPlayer(const AllStarPlayer &rhs){
  79. this->poeni = rhs.poeni;
  80. this->asistencii = rhs.asistencii;
  81. this->skokovi = rhs.skokovi;
  82. }
  83.  
  84. double allStarRating(){
  85. return poeni*0.3+asistencii*0.4+skokovi*0.3;
  86. }
  87.  
  88. void print(){
  89. NBAPlayer::print();
  90. cout << "All Star Rating: " << allStarRating() << endl;
  91. cout << "New Rating: " << (NBAPlayer::rating()+allStarRating())/2 << endl;
  92. }
  93.  
  94. };
  95.  
  96. int main() {
  97.  
  98. char name[50];
  99. char team[40];
  100. double points;
  101. double assists;
  102. double rebounds;
  103. double allStarPoints;
  104. double allStarAssists;
  105. double allStarRebounds;
  106.  
  107. NBAPlayer * players = new NBAPlayer[5];
  108. AllStarPlayer * asPlayers = new AllStarPlayer[5];
  109. int n;
  110. cin >> n;
  111.  
  112. if (n == 1) {
  113.  
  114. cout << "NBA PLAYERS:" << endl;
  115. cout << "=====================================" << endl;
  116. for (int i = 0; i < 5; ++i) {
  117. cin >> name >> team >> points >> assists >> rebounds;
  118. players[i] = NBAPlayer(name,team,points,assists,rebounds);
  119. players[i].print();
  120. }
  121. }
  122. else if (n == 2) {
  123.  
  124. for (int i=0; i < 5; ++i){
  125. cin >> name >> team >> points >> assists >> rebounds;
  126. cin >> allStarPoints >> allStarAssists >> allStarRebounds;
  127. players[i] = NBAPlayer(name,team,points,assists,rebounds);
  128. asPlayers[i] = AllStarPlayer(players[i],allStarPoints,allStarAssists,allStarAssists);
  129. }
  130.  
  131. cout << "NBA PLAYERS:" << endl;
  132. cout << "=====================================" << endl;
  133. for (int i=0; i < 5; ++i)
  134. players[i].print();
  135.  
  136. cout << "ALL STAR PLAYERS:" << endl;
  137. cout << "=====================================" << endl;
  138. for (int i=0; i < 5; ++i)
  139. asPlayers[i].print();
  140.  
  141. }
  142. else if (n == 3) {
  143.  
  144. for (int i=0; i < 5; ++i){
  145. cin >> name >> team >> points >> assists >> rebounds;
  146. cin >> allStarPoints >> allStarAssists >> allStarRebounds;
  147. asPlayers[i] = AllStarPlayer(name, team, points, assists, rebounds,
  148. allStarPoints,allStarAssists,allStarAssists);
  149. }
  150. cout << "ALL STAR PLAYERS:" << endl;
  151. cout << "=====================================" << endl;
  152. for (int i=0; i < 5; ++i)
  153. asPlayers[i].print();
  154.  
  155. }
  156.  
  157. delete [] players;
  158. delete [] asPlayers;
  159. }
Add Comment
Please, Sign In to add comment