Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- class Score {
- public:
- Score() = default;
- Score(const std::string &player_name
- , const std::string &player_position
- , size_t player_score
- , size_t scored_time) : m_player_name{player_name}
- , m_player_position{player_position}
- , m_player_score{player_score}
- , m_scored_time{scored_time} {
- }
- const std::string &GetPlayerName() { return m_player_name; }
- const std::string &GetPlayerPosition() { return m_player_position; }
- const size_t GetScore() { return m_player_score; }
- const size_t GetTime() { return m_scored_time; }
- friend std::ostream &operator<<(std::ostream &os, const Score &other);
- private:
- std::string m_player_name;
- std::string m_player_position;
- size_t m_player_score;
- size_t m_scored_time;
- };
- std::ostream &operator<<(std::ostream &os, const Score &other) {
- os << "Score: " << std::endl
- << "\tPlayer Name : " << other.m_player_name << std::endl
- << "\tPlayer Position : " << other.m_player_position << std::endl
- << "\tPlayer Score : " << other.m_player_score << std::endl
- << "\tScored Time : " << other.m_scored_time << std::endl
- << std::endl;
- return os;
- }
- std::ostream &operator<<(std::ostream &os, const std::vector<Score> &other) {
- for(const auto ¤t : other) os << current;
- os << std::endl;
- return os;
- }
- std::vector<Score> InputTeam(const std::string &team_name, size_t team_size) {
- std::vector<Score> team_score_info;
- std::string player_name;
- std::string player_position;
- size_t player_score;
- size_t scored_time;
- std::cout << "Enter the player names of team " << team_name << ":" << std::endl;
- for (size_t i = 0; i < team_size; i++) {
- std::cout << "Player #" << i << ":" << std::endl;
- std::cout << " Name : ";
- std::cin >> player_name;
- std::cout << " Position(guarda-redes, defesa, médio, avançado) : ";
- std::cin >> player_position;
- std::cout << " Scored Goals : ";
- std::cin >> player_score;
- std::cout << " In what minute scored : ";
- std::cin >> scored_time;
- std::cout << std::endl;
- team_score_info.emplace_back(player_name, player_position, player_score, scored_time);
- }
- return team_score_info;
- }
- int main() {
- std::vector<Score> team_score{InputTeam("Benfica", 2)};
- std::cout << "=====================" << std::endl;
- std::cout << "User entered: "
- << std::endl
- << team_score
- << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement