• Player player2 = {"Vali", 80}; Game game; game.addPlayer(player1); game.addPlayer(player2); game.showPlayers(); return 0;
  • Fanidan tayyorlagan mustaqil ishi




    Download 0,49 Mb.
    bet5/5
    Sana18.05.2024
    Hajmi0,49 Mb.
    #240920
    1   2   3   4   5
    Bog'liq
    Dasturlash

    #include
    #include
    #include
    struct Player {
    std::string name;
    int score;
    };
    class Game {
    private:
    std::map playerScores;

    public:
    void addPlayer(const Player& player) {
    playerScores[player.name] = player.score;
    }
    void showPlayers() {
    std::cout << "O'yinchilar:\n";
    for (const auto& pair : playerScores) {
    std::cout << pair.first << ": " << pair.second << std::endl;
    }
    }
    };
    int main() {
    Player player1 = {"Ali", 100};
    Player player2 = {"Vali", 80};
    Game game;
    game.addPlayer(player1);
    game.addPlayer(player2);
    game.showPlayers();
    return 0;
    }

    Download 0,49 Mb.
    1   2   3   4   5




    Download 0,49 Mb.