Main.cpp #include #include "Deck.h" int main() {     Deck deck;     deck.shuffle();     std::cout << "WAR Card Game\n\n";     std::cout << "Dealing cards...\n\n";     Card player1Card = deck.Deal();     Card player2Card = deck.Deal();     std::cout << "Player 1's card: ";     player1Card.showCard();     std::cout << std::endl;     std::cout << "Player 2's card: ";     player2Card.showCard();     std::cout << std::endl;     int player1Value = player1Card.getValue();     int player2Value = player2Card.getValue();     if (player1Value > player2Value) {         std::cout << "Player 1 wins!" << std::endl;     } else if (player1Value < player2Value) {         std::cout << "Player 2 wins!" << std::endl;     } else {         std::cout << "It's a tie!" << std::endl;     }     return 0; }   Card.h #ifndef CARD_H #define CARD_H class Card { public:     Card();     Card(char r, char s);     int getValue();     void showCard(); private:     char rank;     char suit; }; #endif   Card.cpp #include "Card.h" #include Card::Card() {} Card::Card(char r, char s) {     rank = r;     suit = s; } int Card::getValue() {     // Implement the logic to assign values to each rank of the card     // and return the corresponding value     return 0; } void Card::showCard() {     // Display the rank and suit of the card     std::cout << rank << suit; } arrow_forward Step 3: Deck.h and Deck.cpp Deck.h #ifndef DECK_H #define DECK_H #include "Card.h" class Deck { public:     Deck();     void refreshDeck();     Card Deal();     void shuffle();     int cardsLeft();     void showDeck(); private:     Card cards[52];     int numCards; }; #endif   Deck.cpp #include "Deck.h" #include #include #include Deck::Deck() {     numCards = 52;     refreshDeck(); } void Deck::refreshDeck() {     char ranks[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};     char suits[] = {'H', 'D', 'C', 'S'};     int index = 0;     for (int suit = 0; suit < 4; suit++) {         for (int rank = 0; rank < 13; rank++) {             cards[index] = Card(ranks[rank], suits[suit]);             index++;         }     } } Card Deck::Deal() {     if (numCards > 0) {         numCards--;         return cards[numCards];     }     return Card(); } void Deck::shuffle() {     std::srand(static_cast(std::time(0)));     for (int i = numCards - 1; i > 0; i--) {         int j = std::rand() % (i + 1);         std::swap(cards[i], cards[j]);     } } int Deck::cardsLeft() {     return numCards; } void Deck::showDeck() {     for (int i = 0; i < numCards; i++) {         cards[i].showCard();         std::cout << " ";     }     std::cout << std::endl; }   UML Class Diagrams: A class diagram for each class with appropriate symbols for composition/aggregation and inheritance.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Main.cpp

#include <iostream>
#include "Deck.h"

int main() {
    Deck deck;
    deck.shuffle();

    std::cout << "WAR Card Game\n\n";

    std::cout << "Dealing cards...\n\n";
    Card player1Card = deck.Deal();
    Card player2Card = deck.Deal();

    std::cout << "Player 1's card: ";
    player1Card.showCard();
    std::cout << std::endl;

    std::cout << "Player 2's card: ";
    player2Card.showCard();
    std::cout << std::endl;

    int player1Value = player1Card.getValue();
    int player2Value = player2Card.getValue();

    if (player1Value > player2Value) {
        std::cout << "Player 1 wins!" << std::endl;
    } else if (player1Value < player2Value) {
        std::cout << "Player 2 wins!" << std::endl;
    } else {
        std::cout << "It's a tie!" << std::endl;
    }

    return 0;
}

 

Card.h

#ifndef CARD_H
#define CARD_H

class Card {
public:
    Card();
    Card(char r, char s);
    int getValue();
    void showCard();

private:
    char rank;
    char suit;
};

#endif

 

Card.cpp

#include "Card.h"
#include <iostream>

Card::Card() {}

Card::Card(char r, char s) {
    rank = r;
    suit = s;
}

int Card::getValue() {
    // Implement the logic to assign values to each rank of the card
    // and return the corresponding value
    return 0;
}

void Card::showCard() {
    // Display the rank and suit of the card
    std::cout << rank << suit;
}

arrow_forward
Step 3: Deck.h and Deck.cpp

Deck.h

#ifndef DECK_H
#define DECK_H
#include "Card.h"

class Deck {
public:
    Deck();
    void refreshDeck();
    Card Deal();
    void shuffle();
    int cardsLeft();
    void showDeck();

private:
    Card cards[52];
    int numCards;
};

#endif

 

Deck.cpp

#include "Deck.h"
#include <iostream>
#include <cstdlib>
#include <ctime>

Deck::Deck() {
    numCards = 52;
    refreshDeck();
}

void Deck::refreshDeck() {
    char ranks[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
    char suits[] = {'H', 'D', 'C', 'S'};

    int index = 0;
    for (int suit = 0; suit < 4; suit++) {
        for (int rank = 0; rank < 13; rank++) {
            cards[index] = Card(ranks[rank], suits[suit]);
            index++;
        }
    }
}

Card Deck::Deal() {
    if (numCards > 0) {
        numCards--;
        return cards[numCards];
    }
    return Card();
}

void Deck::shuffle() {
    std::srand(static_cast<unsigned int>(std::time(0)));
    for (int i = numCards - 1; i > 0; i--) {
        int j = std::rand() % (i + 1);
        std::swap(cards[i], cards[j]);
    }
}

int Deck::cardsLeft() {
    return numCards;
}

void Deck::showDeck() {
    for (int i = 0; i < numCards; i++) {
        cards[i].showCard();
        std::cout << " ";
    }
    std::cout << std::endl;
}

 

UML Class Diagrams: A class diagram for each class with appropriate symbols for composition/aggregation and inheritance.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education