Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am given a vague question that says - design and implement a class to represent a playing card, that can be used to play card games. Consider what information you needs to be stored in a card and what you man want to do with a card (accessors/mutators). 2 files are required - card.h and card.cpp.

My impression of this question is that I will need to shuffle then draw a card out of a deck (52 cards). While doing so, I will also need to display the contents of the drawn card only. Can I assume it as such?

So far in my written header file below, I am using array. Is that the best way to go about?

What I have tried:

C++
#ifndef CARD_H
#define CARD_H
#include<string>
#include<iostream>

using namespace std;

class Card
{

    private:
        string suits[4] = {"Hearts", "Diamond", "Clubs". "Spades"};
        string values[13] = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};

    public:
        Card();
        Card(string cardSuit, string cardValue);
        
        void draw();
        void display();
        
};
#endif
Posted
Updated 4-Apr-16 23:27pm

1 solution

I think:
  • it is not a good idea to provide a constructor accepting strings as arguments (an enum would be better).
  • draw should probably update a card state variable (wich is missing in your code)
  • display should take some contextual info as argument (e.g. at what position should the card be displayed?)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900