/***********************
CSC100- Lab 5
Programmer:Zachary Groom
***********************/
#include <iostream>
#include <string>
#include <sstream>
usingnamespace 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';}
elseif (s == 'H' || s=='h')
{suit='H';}
elseif(s == 'S' || s=='s')
{suit='S';}
elseif(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).
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.