Problem with passing data in classes

Hey all I'm having trouble passing my parameters between my classes. Here is my code
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***********************
CSC100- Lab 5
Programmer:Zachary Groom
***********************/
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

// Card class
class CardType
{
	private:
		int rank;  //1-13
		char suit; // D,H,S,C
	public:
		CardType();
		void setCard ( int r, char s);
		void display ();
		int getRank (int r);
		char getSuit (char s);


};

/**************************
 CardType implementation
**************************/
//default constructor -- sets the suit to S and rank to 1
CardType::CardType()
{
	cout<< "Default Set"<<endl;
	rank=1;
	suit='S';
}

// setCard will store the card in the object area
void CardType::setCard(int r, char s)
{	cout<<"Running setCard"<<endl;
	if (r >=0 && r<14)
		rank=r;
	else
		{
		cout<<"Invalid input setting rank to Ace."<<endl;
		rank=1;
		}
	if (s == 'D' || s=='d')
		{suit='D';}
	else if (s == 'H' || s=='h')
		{suit='H';}
	else if(s == 'S' || s=='s')
		{suit='S';}
	else if(s == 'C' || s=='c')
		{suit='C';}
	else
		{
		cout<<"Invalid input setting suit to Spade."<<endl;
		suit='S';
		}

}
int CardType::getRank(int r)
{	cout<<"Running getRank"<<endl;
	rank=r;
	return rank;
}
char CardType::getSuit(char s)
{	cout<<"Running getSuit"<<endl;
	suit=s;
	return suit;
}

/**************************
	Display
**************************/
void CardType::display()
{
	cout<<"The rank is: "<< rank<<"    The suit is: "<<suit<<endl;
}
/**************************
	Driver
**************************/
void main()
{
	CardType c;
	c.display();
	c.getRank(4);
	c.getSuit('H');
	c.setCard(5,'D');
	c.display();

	system("pause");
}


I can't figure out how to get c.setCard() to use the 4 from c.getRank and H to c.getSuit. Any help is much appreciated.
Here are my instructions http://pastebin.com/eGWYcVcS

Your getRank and getSuit functions aren't right. The purpose of get functions is to return the value of a private variable to the caller, without giving them access to the actual value within the class. All that getSuit and getRank should do is return the value that is already held by suit and rank, respectively (if you look at your assignment, getRank is supposed to return an int, while getSuit returns a char. Neither of them should accept any parameters).
So I should change it to this instead?
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/***********************
CSC100- Lab 5
Programmer:Zachary Groom
***********************/
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

// Card class
class CardType
{
	private:
		int rank;  //1-13
		char suit; // D,H,S,C
	public:
		CardType();
		void setCard ( int r, char s);
		void display ();
		int getRank ();
		char getSuit ();
		bool equals();
		int compareTo();
		string toString();
};

/**************************
 CardType implementation
**************************/
//default constructor -- sets the suit to S and rank to 1
CardType::CardType()
{
	cout<< "Default Set"<<endl;
	rank=1;
	suit='S';
}

// setCard will store the card in the object area
void CardType::setCard(int r, char s)
{	cout<<"Running setCard"<<endl;
	if (r >=0 && r<14)
		rank=r;
	else
		{
		cout<<"Invalid input setting rank to Ace."<<endl;
		rank=1;
		}
	if (s == 'D' || s=='d')
		{suit='D';}
	else if (s == 'H' || s=='h')
		{suit='H';}
	else if(s == 'S' || s=='s')
		{suit='S';}
	else if(s == 'C' || s=='c')
		{suit='C';}
	else
		{
		cout<<"Invalid input setting suit to Spade."<<endl;
		suit='S';
		}

}
int CardType::getRank()
{
	cout<<"Running getRank"<<endl;
	return rank;
}
char CardType::getSuit()
{
	cout<<"Running getSuit"<<endl;
	return suit;
}

/**************************
	Display
**************************/
void CardType::display()
{
	cout<<"The rank is: "<< rank<<"    The suit is: "<<suit<<endl;
}
/**************************
	Driver
**************************/
void main()
{
	CardType c;
	c.display();
	c.getRank();
	c.getSuit();
	c.setCard(5,'D');
	c.display();

	system("pause");
}

Then move onto attempting the last three methods?
Yes, that looks better. Good luck!
How would I go about creating the equals() method? I made another CardType under CardType a; I'm just not sure how i would i check if they are both equal. Maybe im missing something with the UML model. What does equals(c:card) : boolean mean? I know it should mean that the type is boolean the name of the method is equals but the (c:Card) confuses me.
Topic archived. No new replies allowed.