Question

C++

Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class

NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program

- Jeupeldul LU Lullatende strings. Normally you would make both of these arrays static, but we havent talked about that yet

*Note that this is composition: a deck of cards has cards, so the DeckOfCards class has a vector of type Card as one of its p

Seven of Diamonds Ten of Hearts Six of Hearts Queen of Diamonds King of Hearts Three of Clubs Deuce of Spades Five of Clubs T

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code Implemented in C++

comments are written for code explanation

Filename:200_assign6.cpp

#include <iostream>
#include <iomanip>
#include "DeckOfCards.h" // DeckOfCards class definition

int main() {
DeckOfCards myDeckOfCards;

// print all 52 Cards in the order in which they are dealt
for (int i = 1; myDeckOfCards.moreCards() && i < 25; ++i) {
// deal and display a Card
std::cout << std::left << std::setw(19)
<< myDeckOfCards.dealCard().toString();

if (i % 4 == 0) // output newline every 4 cards
std::cout << std::endl;
} // end for

std::cout << std::endl;
DeckOfCards newDeckOfCards;
for (int i = 1; newDeckOfCards.moreCards() && i < 55; ++i) {
// deal and display a Card
std::cout << std::left << std::setw(19)
<< newDeckOfCards.dealCard().toString();

if (i % 4 == 0) // output newline every 4 cards
std::cout << std::endl;
} // end for


} // end main


#include <iostream> #include <iomanip> #include DeckOfCards.h // DeckOfCards class definition int main() { DeckOfCards my D

Filename: DeckOfCards.h

#ifndef DECK_OF_CARDS_H
#define DECK_OF_CARDS_H

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

// DeckOfCards class definition
class DeckOfCards {
public:
DeckOfCards(); // constructor initializes deck
Card dealCard(); // deals cards in deck
bool moreCards() const; // are there any more cards left
private:
std::vector< Card > deck; // represents deck of cards
unsigned currentCard; // index of next card to be dealt
}; // end class DeckOfCards

#endif



#ifndef DECK_OF_CARDS_H #define DECK_OF_CARDS_H #include <vector> #include Card.h // DeckOfCards class definition class Dec

Filename: DeckOfCards.cpp

#include "DeckOfCards.h"
#include "Card.h"
#include <iostream>
#include <string>
using namespace std;

DeckOfCards::DeckOfCards() {
currentCard = 0;

for (int i = 0; i < 4; i++) {

for (int j = 0; j < 13; j++) {
Card temp(j, i);
deck.push_back(temp);
}

}

}

Card DeckOfCards::dealCard() {
currentCard++;
return deck.at(currentCard - 1);
}

bool DeckOfCards::moreCards() const {

if (currentCard < deck.size())
return true;
else
return false;

}

1 #include DeckOfCards.h #include Card.h #include <iostream> #include <string> using namespace std; DeckOfCards::DeckOfCa

Filename: Card.cpp

#include <iostream>
#include <string>
#include "Card.h"
using namespace std;

const char* Card::faceNames[ totalFaces ] =
{ "Ace", "Deuce", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };

const char* Card::suitNames[ totalSuits ] =
{ "Hearts", "Diamonds", "Clubs", "Spades" };

Card::Card(int cardFace, int cardSuit) {
face = cardFace;
suit = cardSuit;
}

string Card::toString() const {
string t = " of ";
string FACE = faceNames[face];
string SUIT = suitNames[suit];

string ret = FACE + t + SUIT;
return ret;
}

int Card::getFace() const {

return face;

}

int Card::getSuit() const {

return suit;

}

1 #include <iostream> #include <string> #include Card.h using namespace std; const char* Card: :faceNames[ totalFaces ] = {

Filename:Card.h

#ifndef CARD_H
#define CARD_H

#include <string>

class Card {
public:
static const int totalFaces = 13; // total number of faces
static const int totalSuits = 4; // total number of suits

Card(int cardFace, int cardSuit); // initialize face and suit
std::string toString() const; // returns a string representation
// of a Card

// get the card's face
int getFace() const;

// get the card's suit
int getSuit() const;
private:
int face;
int suit;

static const char* faceNames[totalFaces];
static const char* suitNames[totalSuits];
}; // end class Card

#endif

#ifndef CARD_H #define CARD_H #include <string> class Card { public: static const int totalFaces = 13; // total number of fac

If you like my answer, hit thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards...

    //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards myDeckOfCards; for (int i = 0; myDeckOfCards.moreCards() && i < count; ++i) { std::cout << std::left << std::setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 3) std::cout << std::endl; } } int main() { RunAllTests(); return 0; } //card.hpp #ifndef CARD_HPP_ #define CARD_HPP_ #include <string> class Card { public: static const int totalFaces = 13; static const int totalSuits = 4; Card(int cardFace, int...

  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • how many diamonds are in a deck of cards?

    A deck of cards contains 52 cards. They are divided into four suits: spades, diamonds, clubs and hearts. Each suit has 13 cards: ace through 10, and three picture cards: Jack, Queen, and King. Two suits are red in color: hearts and diamonds. Two suits are black in color: clubs and spades.Use this information to compute the probabilities asked for below and leave them in fraction form. All events are in the context that three cards are dealt from a...

  • Write in Java! Do NOT write two different programs for Deck and Card, it should be...

    Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! !!!!!!!!!!!!!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!!!!!!!!!!!!!!!!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in new deck order. (This is the order of a deck of cards new from the box.) The 2 Array lists...

  • Program 4: C++ The Game of War The game of war is a card game played by children and budding comp...

    Program 4: C++ The Game of War The game of war is a card game played by children and budding computer scientists. From Wikipedia: The objective of the game is to win all cards [Source: Wikipedia]. There are different interpretations on how to play The Game of War, so we will specify our SMU rules below: 1) 52 cards are shuffled and split evenly amongst two players (26 each) a. The 26 cards are placed into a “to play” pile...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • A standard 52-card deck has four 13-card suits: diamonds, hearts, 13-card suit contains cards numbered f...

    A standard 52-card deck has four 13-card suits: diamonds, hearts, 13-card suit contains cards numbered f probability of drawing a black king of hearts clubs, and spades. The diamonds and hearts are red, and the clubs and spades are black Each from 2 to 10, a jack, a queen, a king, and an ace. An experiment consists of drawing 1 card from the standard deck. Find the The probability of choosing a black king of hearts is ype an integer...

  • A standard deck of cards consists of four suits (clubs, diamonds, hearts, and spades), with each...

    A standard deck of cards consists of four suits (clubs, diamonds, hearts, and spades), with each suit containing 13 cards (ace, two through ten, jack, queen, and king) for a total of 52 cards in all. How many 7-card hands will consist of exactly 3 kings and 2 queens?

  • Consider a standard 52-card deck of cards with 13 card values (Ace, King, Queen, Jack, and...

    Consider a standard 52-card deck of cards with 13 card values (Ace, King, Queen, Jack, and 2-10) in each of the four suits (clubs, diamonds, hearts, spades). If a card is drawn at random, what is the probability that it is a spade or a two? Note that "or" in this question refers to inclusive, not exclusive, or.

  • Here is a table showing all 52 cards in a standard deck. Color Face cards Suit...

    Here is a table showing all 52 cards in a standard deck. Color Face cards Suit Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King Hearts AV 2 3 5 6 8v 9 10 J OV Red 7 3. Red Diamonds 4. 2 3. 4. 5. 6 70 8 9. 10. Jo O K Black Spades 49 29 34 4. 54 64 74 84 94 104 JA KA Black Clubs A4 24 34 44 54 64...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT