Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[C++ Coding Question about Card Deck] 1) Program a Card class with these member

ID: 3756148 • Letter: #

Question

[C++ Coding Question about Card Deck]

1) Program a Card class with these member variables:

number – an integer between 1 and 13

suit – an enumerated data type with values { Spade, Heart, Diamond, Club }

description – a string with card name – for example “Spade Ace” or “Heart 5”

A card object with number 1 is an Ace. Number 11 represents a Jack, 12 represents a Queen, and 13 represents a King.

Your class should have set and get member functions to update and return the value of each member variable.

2) Write a main program which creates and displays a deck of 52 cards. The display should look something like this:

3) Separate your class definition and main program from part 2 into two files. Ensure you can build and run your program.

Heart Spade Ace Spade 2 Spade 3 Spade 4 Spade 5 Spade 6 Spade 7 Spade 8 Spade 9 Spade 10 Spade Jack Spade Queen Spade King Diamond Ace Diamond 2 Diamond 3 Diamond 4 Diamond 5 Diamond 6 Diamond 7 Diamond 8 Diamond 9 Diamond 10 Diamond Jack Diamond Queen Diamond King Club Ace Club 2 Club 3 Club 4 Club 5 Club 6 Club 7 Club 8 Club 9 Club 10 Club Jack Club Queen Club King Ace Heart 2 Heart 3 Heart 4 Heart 5 Heart 6 Heart 7 Heart 8 Heart 9 Heart 10 Heart Jack Heart Queen Heart King

Explanation / Answer

#include <assert.h> // For assert()

#include <iostream> // For console output

#include <string> // For std::string

enum class Suits {

SPADES, CLUBS, HEARTS, DIAMONDS

};

std::string toString(Suits s) {

int i;

switch (s) {

case Suits::SPADES: {

for(i=0;i<13;i++)

{

if(i==0)

std::cout<<"Spade Ace"<<std::endl;

else if(i==10)

std::cout<<"Spade Jack"<<std::endl;

else if(i==11)

std::cout<<"Spade Queen"<<std::endl;

else if(i==12)

std::cout<<"Spade King"<<std::endl;

else

std::cout<<"Spade "<<i<<std::endl;

}

  

};

case Suits::CLUBS:{

for(i=0;i<13;i++)

{

if(i==0)

std::cout<<"Clubs Ace"<<std::endl;

else if(i==10)

std::cout<<"Clubs Jack"<<std::endl;

else if(i==11)

std::cout<<"Clubs Queen"<<std::endl;

else if(i==12)

std::cout<<"Clubs King"<<std::endl;

else

std::cout<<"Clubs "<<i<<std::endl;

}

  

};

case Suits::HEARTS:{

for(i=0;i<13;i++)

{

if(i==0)

std::cout<<"Hearts Ace"<<std::endl;

else if(i==10)

std::cout<<"Hearts Jack"<<std::endl;

else if(i==11)

std::cout<<"Hearts Queen"<<std::endl;

else if(i==12)

std::cout<<"Hearts King"<<std::endl;

else

std::cout<<"Hearts "<<i<<std::endl;

}

  

};

case Suits::DIAMONDS:{

for(i=0;i<13;i++)

{

if(i==0)

std::cout<<"Diamonds Ace"<<std::endl;

else if(i==10)

std::cout<<"Diamonds Jack"<<std::endl;

else if(i==11)

std::cout<<"Diamonds Queen"<<std::endl;

else if(i==12)

std::cout<<"Diamonds King"<<std::endl;

else

std::cout<<"Diamonds "<<i<<std::endl;

}

  

};

default:

assert(false);

return "";

}

}

int main() {

std::cout << toString(Suits::SPADES) << std::endl;

std::cout << toString(Suits::CLUBS) << std::endl;

std::cout << toString(Suits::DIAMONDS) << std::endl;

std::cout << toString(Suits::HEARTS) << std::endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote