SlideShare a Scribd company logo
1 of 13
There are 5 C++ files below, Card.h, Card.cpp, Deck.h, Deck.cpp, Main.cpp
Put CArd.h, card.cpp,Deck.h, Deck.cpp under Main.cpp file
i want everything under 1 single CPP file,under 1 single C++ file, 4th time asking, please help
// Card.h
//Create a class Card
#ifndef CARD_H
#define CARD_H
#include<iostream>
using namespace std;
class Card {
//Member variables
private:
char rank, suit;
//Member functions
public:
//Constructors
Card();
Card(char r, char s);
//Set card attributes
void setCard(char r, char s);
//Getter
int getValue();
void showCard();
};
#endif // !CARD_H
Card.cpp
//Implementation of card class
#include "Card.h"
//Constructors
Card::Card() {
rank = suit = ' ';
}
Card::Card(char r, char s) {
rank = r;
suit = s;
}
//Set card attributes
void Card::setCard(char r, char s) {
rank = r;
suit = s;
}
//Getter
int Card::getValue() {
if (rank == 'A') {
return 1;
}
else if (rank == '2') {
return 2;
}
else if (rank == '3') {
return 3;
}
else if (rank == '4') {
return 4;
}
else if (rank == '5') {
return 5;
}
else if (rank == '6') {
return 6;
}
else if (rank == '7') {
return 7;
}
else if (rank == '8') {
return 8;
}
else if (rank == '9') {
return 9;
}
else if (rank == 'K') {
return 10;
}
else if (rank == 'Q') {
return 10;
}
else {
return 10;
}
}
//Show a carrd representation
void Card::showCard() {
cout << rank << suit<<".";
}
Deck.h
//Create a deck of cards
#ifndef DECK_H
#define DECK_H
#include "Card.h"
class Deck {
//Member variables
private:
Card deck[52];
int cardsCnt;
//Member variables
public:
//Constructor
Deck();
//Create a fresh deck
void refreshDeck();
//Get a card from top
Card deal();
//Shuffle
void shuffle();
//Number of cards left in deck
int cardsLeft();
//Display deck
void displayDeck();
};
#endif // !DECK_H
Deck.cpp
//Implementation of deck class
#include "Deck.h"
//Constructor
Deck::Deck() {
char ranks[] = { 'A','1','2','3','4','5','6','7','8','9','J','Q','K' };
char suits[] = { 'S','H','D','C' };
int k = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++)
{
deck[k++] = Card(ranks[j], suits[i]);
}
}
cardsCnt = 52;
}
//Create a fresh deck
void Deck::refreshDeck() {
char ranks[] = { 'A','1','2','3','4','5','6','7','8','9','J','Q','K' };
char suits[] = { 'S','H','D','C' };
int k = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++)
{
deck[k++] = Card(ranks[j], suits[i]);
}
}
cardsCnt = 52;
}
//Get a card from top
Card Deck::deal() {
Card c=deck[cardsCnt - 1];
cardsCnt--;
return c;
}
//Shuffle
void Deck::shuffle() {
srand(0);
for (int i = 0; i <cardsCnt; i++)
{
int r = i + (rand() % (52 - i));
Card temp = deck[i];
deck[i] = deck[r];
deck[r] = temp;
}
}
//Number of cards left in deck
int Deck::cardsLeft() {
return cardsCnt;
}
//Display deck
void Deck :: displayDeck() {
for (int i = 0; i < 52; i++) {
if (i % 13 == 0 && i != 0) {
cout << endl;
deck[i].showCard();
cout << " ";
}
else {
deck[i].showCard();
cout << " ";
}
}
}
Main.cpp
#include "Deck.h"
#include <stack>
//Create object of Deck class
Deck deck;
//Function prototypes
void playGame();
bool isPrime(int val);
void printStackReverse(stack<Card> s);
int main()
{
int ch;
//Loop until exit
while (true) {
//User choices
cout << "Welcome to Solitaire Prime!n1) New Deckn2) Display Deckn3) Shuffle Deckn4)
Play Solitairen5) ExitnnEnter choice: ";
cin >> ch;
//Switch according to choice
switch (ch) {
//Create a new deck
case 1:
deck.refreshDeck();
cout << "nNew deck createdn";
break;
//Display deck
case 2:
cout << "nDeck:n";
deck.displayDeck();
cout << endl;
break;
//Shuffle deck of cards
case 3:
deck.shuffle();
cout << "nShuffled deck createdn";
break;
//Play game
case 4:
playGame();
break;
//End
case 5:
cout << "nThank you!!!n";
exit(0);
break;
default:
cout << "nIncorrect choicen";
break;
}
cout << endl;
}
}
//Function simulate a play
void playGame() {
cout << deck.cardsLeft() << endl;
int piles = 0,sum=0;
stack<Card> hand;
cout << "nPlaying Solitaire game!!nn";
//Play game until deck cards count reach 0
while (deck.cardsLeft() != 0) {
//Otherwise take a card check sum
Card c = deck.deal();
sum += c.getValue();
//If print then clear and increment piles count
if (isPrime(sum)) {
hand.push(c);
//Display stack reverse order
printStackReverse(hand);
hand = stack<Card>();
cout << " Prime: " << sum << endl;
piles++;
sum = 0;
}
//Otherwise add into stack
else {
hand.push(c);
}
}
if (sum!=0) {
printStackReverse(hand);
hand = stack<Card>();
cout << " Losern";
}
else {
cout << "nWinner in " << piles << " piles!n";
}
}
//Check passed value is prime or not
bool isPrime(int val) {
bool prime = true;
if (val == 0 || val == 1) {
prime = false;
}
else {
for (int i = 2; i <= val / 2; ++i) {
if (val % i == 0) {
prime = false;
break;
}
}
}
if (prime)
return true;
else
return false;
}
//Display stack in reverse order
void printStackReverse(stack<Card> s)
{
if (s.empty())
return;
Card x = s.top();
s.pop();
printStackReverse(s);
x.showCard();
cout << " ";
s.push(x);
}

More Related Content

Similar to There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx

BlackJackBlackjack.c Blackjack.c Defines the entry point .docx
BlackJackBlackjack.c Blackjack.c  Defines the entry point .docxBlackJackBlackjack.c Blackjack.c  Defines the entry point .docx
BlackJackBlackjack.c Blackjack.c Defines the entry point .docx
AASTHA76
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
ADITIEYEWEAR
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
feelinggifts
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
trishulinoverseas1
 
Introduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfIntroduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdf
charanjit1717
 
Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdf
trishulinoverseas1
 
Goal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdfGoal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdf
aaicommunication34
 
FaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfFaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdf
abifancystore
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdf
fazilfootsteps
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
Part I.pdf
Part I.pdfPart I.pdf
Part I.pdf
support58
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
fsenterprises
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
PiersRCoThomsonw
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 

Similar to There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx (20)

BlackJackBlackjack.c Blackjack.c Defines the entry point .docx
BlackJackBlackjack.c Blackjack.c  Defines the entry point .docxBlackJackBlackjack.c Blackjack.c  Defines the entry point .docx
BlackJackBlackjack.c Blackjack.c Defines the entry point .docx
 
import javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdfimport javautilLinkedList import javautilQueue import .pdf
import javautilLinkedList import javautilQueue import .pdf
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdfHere is the game description- Here is the sample game- Goal- Your goal (1).pdf
Here is the game description- Here is the sample game- Goal- Your goal (1).pdf
 
Introduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdfIntroduction Now that the Card and Deck classes are completed, th.pdf
Introduction Now that the Card and Deck classes are completed, th.pdf
 
Here is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdfHere is the game description- Here is the sample game- Here is the req.pdf
Here is the game description- Here is the sample game- Here is the req.pdf
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Goal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdfGoal- Your goal in this assignment is to write a Java program that sim.pdf
Goal- Your goal in this assignment is to write a Java program that sim.pdf
 
FaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdfFaceUp card game In this assignment we will implement a made.pdf
FaceUp card game In this assignment we will implement a made.pdf
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdf
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
Part I.pdf
Part I.pdfPart I.pdf
Part I.pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
DMA.pptx
DMA.pptxDMA.pptx
DMA.pptx
 

More from AustinIKkNorthy

Three conditions characterize difficult manageriat decisions concernin.docx
Three conditions characterize difficult manageriat decisions concernin.docxThree conditions characterize difficult manageriat decisions concernin.docx
Three conditions characterize difficult manageriat decisions concernin.docx
AustinIKkNorthy
 
This is the -declare-txt-- In Congress- July 4- 1776 The unanimous De.docx
This is the -declare-txt--  In Congress- July 4- 1776 The unanimous De.docxThis is the -declare-txt--  In Congress- July 4- 1776 The unanimous De.docx
This is the -declare-txt-- In Congress- July 4- 1776 The unanimous De.docx
AustinIKkNorthy
 

More from AustinIKkNorthy (20)

Threats to auditor independence can come from various sources- Which o.docx
Threats to auditor independence can come from various sources- Which o.docxThreats to auditor independence can come from various sources- Which o.docx
Threats to auditor independence can come from various sources- Which o.docx
 
Three conditions characterize difficult manageriat decisions concernin.docx
Three conditions characterize difficult manageriat decisions concernin.docxThree conditions characterize difficult manageriat decisions concernin.docx
Three conditions characterize difficult manageriat decisions concernin.docx
 
this needs to be done in matlab Assignment 1 (5 points) Communicate wi.docx
this needs to be done in matlab Assignment 1 (5 points) Communicate wi.docxthis needs to be done in matlab Assignment 1 (5 points) Communicate wi.docx
this needs to be done in matlab Assignment 1 (5 points) Communicate wi.docx
 
This is the -declare-txt-- In Congress- July 4- 1776 The unanimous De.docx
This is the -declare-txt--  In Congress- July 4- 1776 The unanimous De.docxThis is the -declare-txt--  In Congress- July 4- 1776 The unanimous De.docx
This is the -declare-txt-- In Congress- July 4- 1776 The unanimous De.docx
 
This graphic (above) illustrates which process- Complete the following.docx
This graphic (above) illustrates which process- Complete the following.docxThis graphic (above) illustrates which process- Complete the following.docx
This graphic (above) illustrates which process- Complete the following.docx
 
Think about a closed economy with two types of households- the wealthy.docx
Think about a closed economy with two types of households- the wealthy.docxThink about a closed economy with two types of households- the wealthy.docx
Think about a closed economy with two types of households- the wealthy.docx
 
There is a problem completing the replication of linear chromosomes at.docx
There is a problem completing the replication of linear chromosomes at.docxThere is a problem completing the replication of linear chromosomes at.docx
There is a problem completing the replication of linear chromosomes at.docx
 
There are two traits in Homo heidlebergensis that foreshadows the evol.docx
There are two traits in Homo heidlebergensis that foreshadows the evol.docxThere are two traits in Homo heidlebergensis that foreshadows the evol.docx
There are two traits in Homo heidlebergensis that foreshadows the evol.docx
 
There is a 20- chance that Cinderella will lose her left shoe as she s.docx
There is a 20- chance that Cinderella will lose her left shoe as she s.docxThere is a 20- chance that Cinderella will lose her left shoe as she s.docx
There is a 20- chance that Cinderella will lose her left shoe as she s.docx
 
There are many advantages of ICT that benefit the marketing function o.docx
There are many advantages of ICT that benefit the marketing function o.docxThere are many advantages of ICT that benefit the marketing function o.docx
There are many advantages of ICT that benefit the marketing function o.docx
 
There are three horizontal sedimentary layers stacked on top of each o.docx
There are three horizontal sedimentary layers stacked on top of each o.docxThere are three horizontal sedimentary layers stacked on top of each o.docx
There are three horizontal sedimentary layers stacked on top of each o.docx
 
There are ongoing concerns about how accurate the CPI is in measuring.docx
There are ongoing concerns about how accurate the CPI is in measuring.docxThere are ongoing concerns about how accurate the CPI is in measuring.docx
There are ongoing concerns about how accurate the CPI is in measuring.docx
 
There are 12 cualfed candidates- and olficers can also serve on the co.docx
There are 12 cualfed candidates- and olficers can also serve on the co.docxThere are 12 cualfed candidates- and olficers can also serve on the co.docx
There are 12 cualfed candidates- and olficers can also serve on the co.docx
 
The Wall had protected Westeros from the dangers of the wildlings for.docx
The Wall had protected Westeros from the dangers of the wildlings for.docxThe Wall had protected Westeros from the dangers of the wildlings for.docx
The Wall had protected Westeros from the dangers of the wildlings for.docx
 
The U-S- remains commited to a policy of funding health care through a.docx
The U-S- remains commited to a policy of funding health care through a.docxThe U-S- remains commited to a policy of funding health care through a.docx
The U-S- remains commited to a policy of funding health care through a.docx
 
The two major cavities are the dorsal cavity and the ventral cavity 17.docx
The two major cavities are the dorsal cavity and the ventral cavity 17.docxThe two major cavities are the dorsal cavity and the ventral cavity 17.docx
The two major cavities are the dorsal cavity and the ventral cavity 17.docx
 
the total population- 83-190-556 Femsie Regulaben Apte 35-30 Ferisie.docx
the total population- 83-190-556  Femsie Regulaben Apte 35-30 Ferisie.docxthe total population- 83-190-556  Femsie Regulaben Apte 35-30 Ferisie.docx
the total population- 83-190-556 Femsie Regulaben Apte 35-30 Ferisie.docx
 
The theoretical level serving as the interface between phonology and s.docx
The theoretical level serving as the interface between phonology and s.docxThe theoretical level serving as the interface between phonology and s.docx
The theoretical level serving as the interface between phonology and s.docx
 
The term (1- ) refers to- the level of consistency the level of co.docx
The term (1- ) refers to-   the level of consistency   the level of co.docxThe term (1- ) refers to-   the level of consistency   the level of co.docx
The term (1- ) refers to- the level of consistency the level of co.docx
 
The text provides a very brief introduction to Zero Trust Architecture.docx
The text provides a very brief introduction to Zero Trust Architecture.docxThe text provides a very brief introduction to Zero Trust Architecture.docx
The text provides a very brief introduction to Zero Trust Architecture.docx
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx

  • 1. There are 5 C++ files below, Card.h, Card.cpp, Deck.h, Deck.cpp, Main.cpp Put CArd.h, card.cpp,Deck.h, Deck.cpp under Main.cpp file i want everything under 1 single CPP file,under 1 single C++ file, 4th time asking, please help // Card.h //Create a class Card #ifndef CARD_H #define CARD_H #include<iostream> using namespace std; class Card { //Member variables private: char rank, suit; //Member functions public: //Constructors Card(); Card(char r, char s); //Set card attributes void setCard(char r, char s); //Getter int getValue(); void showCard();
  • 2. }; #endif // !CARD_H Card.cpp //Implementation of card class #include "Card.h" //Constructors Card::Card() { rank = suit = ' '; } Card::Card(char r, char s) { rank = r; suit = s; } //Set card attributes void Card::setCard(char r, char s) { rank = r; suit = s; } //Getter int Card::getValue() { if (rank == 'A') { return 1; }
  • 3. else if (rank == '2') { return 2; } else if (rank == '3') { return 3; } else if (rank == '4') { return 4; } else if (rank == '5') { return 5; } else if (rank == '6') { return 6; } else if (rank == '7') { return 7; } else if (rank == '8') { return 8; } else if (rank == '9') { return 9;
  • 4. } else if (rank == 'K') { return 10; } else if (rank == 'Q') { return 10; } else { return 10; } } //Show a carrd representation void Card::showCard() { cout << rank << suit<<"."; } Deck.h //Create a deck of cards #ifndef DECK_H #define DECK_H #include "Card.h" class Deck { //Member variables private:
  • 5. Card deck[52]; int cardsCnt; //Member variables public: //Constructor Deck(); //Create a fresh deck void refreshDeck(); //Get a card from top Card deal(); //Shuffle void shuffle(); //Number of cards left in deck int cardsLeft(); //Display deck void displayDeck(); }; #endif // !DECK_H Deck.cpp //Implementation of deck class #include "Deck.h" //Constructor Deck::Deck() {
  • 6. char ranks[] = { 'A','1','2','3','4','5','6','7','8','9','J','Q','K' }; char suits[] = { 'S','H','D','C' }; int k = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { deck[k++] = Card(ranks[j], suits[i]); } } cardsCnt = 52; } //Create a fresh deck void Deck::refreshDeck() { char ranks[] = { 'A','1','2','3','4','5','6','7','8','9','J','Q','K' }; char suits[] = { 'S','H','D','C' }; int k = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { deck[k++] = Card(ranks[j], suits[i]); } } cardsCnt = 52;
  • 7. } //Get a card from top Card Deck::deal() { Card c=deck[cardsCnt - 1]; cardsCnt--; return c; } //Shuffle void Deck::shuffle() { srand(0); for (int i = 0; i <cardsCnt; i++) { int r = i + (rand() % (52 - i)); Card temp = deck[i]; deck[i] = deck[r]; deck[r] = temp; } } //Number of cards left in deck int Deck::cardsLeft() { return cardsCnt; } //Display deck
  • 8. void Deck :: displayDeck() { for (int i = 0; i < 52; i++) { if (i % 13 == 0 && i != 0) { cout << endl; deck[i].showCard(); cout << " "; } else { deck[i].showCard(); cout << " "; } } } Main.cpp #include "Deck.h" #include <stack> //Create object of Deck class Deck deck; //Function prototypes void playGame(); bool isPrime(int val); void printStackReverse(stack<Card> s); int main()
  • 9. { int ch; //Loop until exit while (true) { //User choices cout << "Welcome to Solitaire Prime!n1) New Deckn2) Display Deckn3) Shuffle Deckn4) Play Solitairen5) ExitnnEnter choice: "; cin >> ch; //Switch according to choice switch (ch) { //Create a new deck case 1: deck.refreshDeck(); cout << "nNew deck createdn"; break; //Display deck case 2: cout << "nDeck:n"; deck.displayDeck(); cout << endl; break; //Shuffle deck of cards case 3: deck.shuffle();
  • 10. cout << "nShuffled deck createdn"; break; //Play game case 4: playGame(); break; //End case 5: cout << "nThank you!!!n"; exit(0); break; default: cout << "nIncorrect choicen"; break; } cout << endl; } } //Function simulate a play void playGame() { cout << deck.cardsLeft() << endl; int piles = 0,sum=0; stack<Card> hand;
  • 11. cout << "nPlaying Solitaire game!!nn"; //Play game until deck cards count reach 0 while (deck.cardsLeft() != 0) { //Otherwise take a card check sum Card c = deck.deal(); sum += c.getValue(); //If print then clear and increment piles count if (isPrime(sum)) { hand.push(c); //Display stack reverse order printStackReverse(hand); hand = stack<Card>(); cout << " Prime: " << sum << endl; piles++; sum = 0; } //Otherwise add into stack else { hand.push(c); } } if (sum!=0) { printStackReverse(hand);
  • 12. hand = stack<Card>(); cout << " Losern"; } else { cout << "nWinner in " << piles << " piles!n"; } } //Check passed value is prime or not bool isPrime(int val) { bool prime = true; if (val == 0 || val == 1) { prime = false; } else { for (int i = 2; i <= val / 2; ++i) { if (val % i == 0) { prime = false; break; } } } if (prime) return true;
  • 13. else return false; } //Display stack in reverse order void printStackReverse(stack<Card> s) { if (s.empty()) return; Card x = s.top(); s.pop(); printStackReverse(s); x.showCard(); cout << " "; s.push(x); }