Question: How to break this to 5 files which is main.cpp , Deck.h , Deck.cpp , Card.cpp , Card.h Please break it and also do the

How to break this to 5 files which is main.cpp, Deck.h, Deck.cpp, Card.cpp, Card.h
Please break it and also do the output if it work.
Main.cpp
#include
#include "Deck.h"
#include "Card.h"
int main(){
Deck deck;
std::string player1, player2;
//1. Create a new deck
std::cout << "Enter player 1 name: ";
std::cin >> player1;
std::cout << "Enter player 2 name: ";
std::cin >> player2;
//2. Print unshuffled deck
std::cout << "Unshuffled deck:" << std::endl;
deck.print();
//3. Shuffle the deck
deck.shuffle();
//4. Print shuffled deck
std::cout << "Shuffled deck:" << std::endl;
deck.print();
//5. Play 26 rounds (52 cards, 2 per round)
int player1Wins =0, player2Wins =0, ties =0;
for (int i =0; i <26; ++i){
Card card1= deck.deal();
Card card2= deck.deal();
std::cout << "Round "<<(i +1)<<":
"<< player1<<" Card: ";
card1.print();
std::cout <<""<< player2<<" Card: ";
card2.print();
std::cout << std::endl;
int result = card1.compare(card2);
if (result ==1){
std::cout << player1<<" wins this round!" << std::endl;
++player1Wins;
} else if (result ==-1){
std::cout << player2<<" wins this round!" << std::endl;
++player2Wins;
} else {
std::cout << "It's a tie!" << std::endl;
++ties;
}
}
//6. Print final statistics
std::cout <<"
Final Statistics:
";
std::cout << player1<<" wins: "<< player1Wins << std::endl;
std::cout << player2<<" wins: "<< player2Wins << std::endl;
std::cout << "Ties: "<< ties << std::endl;
return 0;
}
Card.h
#ifndef CARD_H
#define CARD_H
class Card {
private:
char rank;
char suit;
public:
// Constructor to create card with given suit and rank
Card(char r, char s) : rank(r), suit(s){}
// Default constructor
Card() : rank('0'), suit('0'){}
// Function to print card details
void print() const {
std::cout << rank << suit <<"";
}
// Function to compare two cards' ranks
int compare(const Card& other) const {
if (rank == other.rank){
return 0; // Tie
} else if (rank > other.rank){
return 1; // Win
} else {
return -1; // Lose
}
}
};
#endif
Deck.h
#ifndef DECK_H
#define DECK_H
#include "Card.h"
#include
#include
#include
class Deck {
private:
Card cards[52]; // Array to hold 52 cards
int currentCard;
public:
// Constructor to create a deck of 52 cards
Deck(){
char suits[]={'H','D','S','C'};
char ranks[]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
currentCard =0;
// Populate deck with cards
for (int i =0; i <4; ++i){
for (int j =0; j <13; ++j){
cards[currentCard++]= Card(ranks[j], suits[i]);
}
}
currentCard =0; // Reset to start dealing from the top of the deck
}
// Shuffle the deck
void shuffle(){
srand(time(0)); // Seed random number generator
for (int i =0; i <52; ++i){
int r = i +(rand()%(52- i));
Card temp = cards[i];
cards[i]= cards[r];
cards[r]= temp;
}
}
// Deal a card from the deck
Card deal(){
return cards[currentCard++];
}
// Print all cards in the deck
void print() const {
for (int i =0; i <52; ++i){
cards[i].print();
if ((i +1)%13==0)
std::cout << std::endl;
}
}
};
Please break the card and deck to two file which are .h and .cpp
And also test the program, thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!