Advertisement
ivodevweb

Untitled

Dec 17th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. class Score {
  5. public:
  6.   Score() = default;
  7.  
  8.   Score(const std::string &player_name
  9.       , const std::string &player_position
  10.       , size_t player_score
  11.       , size_t scored_time) : m_player_name{player_name}
  12.                             , m_player_position{player_position}
  13.                             , m_player_score{player_score}
  14.                             , m_scored_time{scored_time} {
  15.   }
  16.  
  17.   const std::string &GetPlayerName() { return m_player_name; }
  18.   const std::string &GetPlayerPosition() { return m_player_position; }
  19.   const size_t GetScore() { return m_player_score; }
  20.   const size_t GetTime() { return m_scored_time; }
  21.  
  22.   friend std::ostream &operator<<(std::ostream &os, const Score &other);
  23.  
  24. private:
  25.   std::string m_player_name;
  26.   std::string m_player_position;
  27.   size_t m_player_score;
  28.   size_t m_scored_time;
  29. };
  30.  
  31. std::ostream &operator<<(std::ostream &os, const Score &other) {
  32.   os << "Score: " << std::endl
  33.      << "\tPlayer Name     : " << other.m_player_name << std::endl
  34.      << "\tPlayer Position : " << other.m_player_position << std::endl
  35.      << "\tPlayer Score    : " << other.m_player_score << std::endl
  36.      << "\tScored Time     : " << other.m_scored_time << std::endl
  37.      << std::endl;
  38.   return os;
  39. }
  40.  
  41. std::ostream &operator<<(std::ostream &os, const std::vector<Score> &other) {
  42.   for(const auto &current : other) os << current;
  43.   os << std::endl;
  44.   return os;
  45. }
  46.  
  47.  
  48. std::vector<Score> InputTeam(const std::string &team_name, size_t team_size) {
  49.   std::vector<Score> team_score_info;
  50.   std::string player_name;
  51.   std::string player_position;
  52.   size_t player_score;
  53.   size_t scored_time;
  54.  
  55.   std::cout << "Enter the player names of team " << team_name << ":" << std::endl;
  56.  
  57.   for (size_t i = 0; i < team_size; i++) {
  58.     std::cout << "Player #" << i << ":" << std::endl;
  59.     std::cout << "    Name : ";
  60.     std::cin >> player_name;
  61.     std::cout << "    Position(guarda-redes, defesa, médio, avançado) : ";
  62.     std::cin >> player_position;
  63.     std::cout << "    Scored Goals : ";
  64.     std::cin >> player_score;
  65.     std::cout << "    In what minute scored : ";
  66.     std::cin >> scored_time;
  67.     std::cout << std::endl;
  68.  
  69.     team_score_info.emplace_back(player_name, player_position, player_score, scored_time);
  70.   }
  71.  
  72.   return team_score_info;
  73. }
  74.  
  75.  
  76.  
  77. int main() {
  78.     std::vector<Score> team_score{InputTeam("Benfica", 2)};
  79.  
  80.     std::cout << "=====================" << std::endl;
  81.  
  82.     std::cout << "User entered: "
  83.               << std::endl
  84.               << team_score
  85.               << std::endl;
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement