51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
// heart inherits from redcard
|
|
#include "heart.h"
|
|
|
|
Heart::Heart(int v) : RedCard::RedCard(v) // Parameterized constructor that creates a black card with value v and unknown suit
|
|
{
|
|
Card::SetSuit('H'); // sets suit to H
|
|
}
|
|
RedCard::Card ht; // allows access to functions in Card
|
|
|
|
string Heart::Description() const // Outputs card characteristics - value and color and suit as a string
|
|
{
|
|
int Hval = Card::GetValue();
|
|
string Hcol = Card::GetColor();
|
|
char Hst = Card::GetSuit();
|
|
string d = "Value = "; // temporary variable used to accumulate result
|
|
|
|
switch (Hval) // Append card value to variable's value
|
|
{
|
|
case 2: d = d + "2"; break; // Number cards
|
|
case 3: d = d + "3"; break;
|
|
case 4: d = d + "4"; break;
|
|
case 5: d = d + "5"; break;
|
|
case 6: d = d + "6"; break;
|
|
case 7: d = d + "7"; break;
|
|
case 8: d = d + "8"; break;
|
|
case 9: d = d + "9"; break;
|
|
case 10: d = d + "10"; break;
|
|
|
|
case 11: d = d + "J"; break; // Face cards
|
|
case 12: d = d + "Q"; break;
|
|
case 13: d = d + "K"; break;
|
|
case 14: d = d + "A"; break;
|
|
|
|
default: d = d + "?"; break; // Unknown card
|
|
}
|
|
d = d + ", Color = "; // adds color to output string
|
|
if (Hcol=="black") d = d + "black";
|
|
if (Hcol=="red") d = d + "red";
|
|
else d=+ "unknown";
|
|
// appends suit to output string
|
|
d =+ ", Suit = ";
|
|
switch (Hst)
|
|
{
|
|
case 'H': d =+ "H"; break;
|
|
case 'C': d =+ 'C'; break;
|
|
case 'D': d =+ 'D'; break;
|
|
case 'U': d =+ 'U'; break;
|
|
}
|
|
|
|
return d; // Return string describing card value
|
|
} |