I would like a code review on the coding I did for my assignment. The reason I have asked here is because my lecturer has no intention of going through (Don't ask me why, I asked before and he said no..) and I have no idea if I am doing it right or not.. All my other classmates seems to have different answers too, some have deck class, shuffle function etc..
Anyway the question is asking the user to design and implement a class that represent a playing card in which it 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).
In this assignment, only 2 files are required - 1 header and 1 implementation file. Kindly see the following:
Header file
#ifndef CARD_H
#define CARD_H
#include<string>
using namespace std;
class card
{
private:
string cardSuit;
string cardValue;
public:
// Constructor
string displayCard(string, string);
// Member Functions
string getSuit();
string getValue();
// Default
card();
};
#endif
Implementation File
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include "card.h"
using namespace std;
card::card()
{
srand(time(0));
cardSuit = getSuit();
cardValue = getValue();
}
string card::displayCard(string suit, string value)
{
return cardSuit + " of " + cardValue;
}
string card::getSuit()
{
string arrSuits[] = {"HEARTS", "DIAMONDS", "CLUBS", "SPADES"};
// 1 out of 4 suits is choose randomly
int randSuits = rand() % 4;
return arrSuits[randSuits];
}
string card::getValue()
{
string arrValues[] = {"ACE", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"};
// 1 out of 13 values is choose randomly
int randValues = rand() % 13;
return arrValues[randValues];
}
As I have only started out in C++, do pardon me if my coding format is wrong etc.