Classes - Card Game Class & Array (help)

Hey guys, this is my first post here!

I have an assignment for college, which is also a personal assignment that I wanted to do. My idea is to create a simple Card class to be used for card games.

Since I have to hand it in class by the end of the week, I didn't want to elaborate on it extensively... for now at least.

As of now, the problem is that my Card.h class is not being included, even thought my include command looks proper:

#include "Card.h"

All I have done is the Class (.h) file, the Constructor (.cpp) and the main file. Here they are:

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
#ifndef CARD_H
#define CARD_H

#include<stdio.h>
#include<string>
#include<cstdio>
#include<iostream>
 
class Card
{
public:
       
   Card();
   Card(int);
   int get_value() const;
   string get_type(int) const;

private:
        int value;
        int _value;
};

#endif 


Card.cpp
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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <cstdio>

#include "Card.h"

using namespace std;

Card::Card() 
{}

Card::Card(int value)
{  
    _value = value;
}

int Card::get_value() const
{
    return _value;
}

string Card::get_type(int value) const
{
       if (!value) return "ERROR";
       if (value >= 0 && value <= 12) return "Hearts";
       if (value >= 13 && value <= 25) return "Spades";
       if (value >= 26 && value <= 38) return "Clubs";
       if (value >= 39 && value <= 51) return "Diamonds";
       
       else return "ERROR";
       
}


main.cpp
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
55
56
57
58
59
60
61
62
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <cstdio>
#include <iostream>

#include "Card.h"
#include "Card.cpp"

using namespace std;



int main()
{
    // Generates card deck - array of cards
    Card deck[51];
    
    // Control variables
    int rndm = 0;
    int cont = 0;
    int temp = 0;
    
    // Give cards a value and type
    while (temp <= 51) {
          
          deck[temp] = Card(temp);
          temp++;
    }
    
    // Scramble the deck
    
    // Generate random seed
    srand ( time(NULL) );
    
    int scrb = 0;
    temp = 0;
    /*
    while (scrb <= 520) {
          
          rndm = rand() % 52;
          cont = deck[temp];
          deck[temp] = deck[rndm];
          deck[rndm] = cont;
          
          temp++;
          scrb++;
    }
    */
    
    int i = 0;
    
    while (i <= 51) {
          cout << "Card [" << i << "] value is: " << deck[i].get_value() << endl;
          i++;
          }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


That's pretty much it. I've tried adding/removing lib's that's why there's so many included in these examples, aswell as passing the array by reference and without it.

The error I get is:

In file included in main.cpp (line 9 from main.cpp)

I just started this 30 mins ago and all I wanted to do (so far) was to generate the card deck and randomize the cards. I'm using a convention for the types of cards as an integer "value", as seen in code. If any one else has suggestions or other ideas as to how I could approach it let me know.

Thanks for your time!
You shouldn't be #including cpp files. Header files only! Multiple source files are joined by the linker, not the compiler.

Also, what's the actual error message? All you told us was what line it's on.
Topic archived. No new replies allowed.