Help on approaching "hearts"(card game) in c++

I have recently received a new assignment for my cs course, and I am asked to make a game of "hearts" in c++.
So here's the question, the question has provided 3 files, a card.h, card.cc, and a main.
--------------------------------
card.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef __CARD_H__
#define __CARD_H__

using namespace std;

#include <string>

class Card {
    public:
	// Some (static) constants and types for rank and suit.
	enum Rank {Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten,
		    Jack, Queen, King, Ace};
	static const string RankName;
	static const int numRanks;
	enum Suit {Spades, Diamonds, Clubs, Hearts};
	static const string SuitName;
	static const int numSuits;
	static const int numCards;
	// Two special cards, which are compared by value in various places
	static const Card TwoOfClubs;
	static const Card QueenOfSpades;

	// Constructors and destructor.
	// Cxr of no args creates the Ace of Spades, cos sometimes you
	// just gotta have a card, which you can then overwrite.
	Card ();
	// Preferred cxr
	Card (Rank r, Suit s);
	// Takes a char string of length 2, which better be legal
	Card (string sCard);
	~Card ();

	// Accessor fcns
	Rank getRank () const;
	Suit getSuit () const;
	int getHeartsValue () const;

	// Static utility function to check if a two char string 
	// represents a legal card value
	static bool stringIsALegalCard (string s);

    private:
	Rank rank;
	Suit suit;
};

// Overloaded operators: We will define them in Card.cc so we need to
// make their prototypes visible here for clients.
extern bool operator== (const Card& c1, const Card& c2);
extern bool operator< (const Card& c1, const Card& c2);
extern ostream& operator<< (ostream &out, const Card &c);
extern istream& operator>> (istream& in, Card& c);

#endif /* __CARD_H__ */ 

---------------------------------
//card.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <cassert>
#include <iostream>
#include "Card.h"

using namespace std;

const string Card::RankName = "23456789TJQKA";
const string Card::SuitName = "SDCH";
const int Card::numRanks = RankName.length();
const int Card::numSuits = SuitName.length();
const int Card::numCards = Card::numRanks * Card::numSuits;
const Card Card::TwoOfClubs (Card::Two, Card::Clubs);
const Card Card::QueenOfSpades (Card::Queen, Card::Spades);

// We'll give you this one.
Card::Card() : rank(Ace), suit(Spades) {}

// Now you do the rest. 

-------------------------------------
//and the main file
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
#include "Card.h"
using namespace std;

int main (int argc, char* argv[]) {
	Card c(Card::Ace, Card::Spades);
	cout << "Enter a card: ";
	while (cin >> c) {
		cout << "   and the new card is: " << c << endl;
		cout << "Enter a card: ";
	}
}

----------------------------
The instruction asks me to add any missing function/implementions in card.cc (I am not allowed to change card.h) in order to make the main file work in the way it should.
So my first question is really simple, should I continue making all the cards in card.cc file after the spades ace? what should be my first step/approach?

ps: I admit that I have been slacking in the course throughout the term, but I would really want to catch back up now!
I really appreciate all your helps and suggestions!
Last edited on
Read the textbook (Chapter 11 & 14).

You first line in .cc should be something like this:

Card::Card(Rank r, Suit s) : rank(r), suit(s) {}
Topic archived. No new replies allowed.