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
|
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string.h>
using namespace std;
class card{
int suit; //Hearts=1,Clubs=2,Spades=3.Diamonds=4
int cardnum; //A=1,2-10=2-10,J=11,Q=12,K=13
public:
card(int s,int cn);
int getSuit();
int getCardNum();
char* toString();
};
card::card(int s,int cn){
suit = s;
cardnum = cn;
}
int card::getSuit(){
return suit;
}
int card::getCardNum(){
return cardnum;
}
char* card::toString(){
char str[20] = "";
char numstr[6];
char conststr[5] = " of ";
char suitstr[9];
switch(cardnum){
case 1:
strcpy_s(numstr,"Ace");
break;
case 11:
strcpy_s(numstr,"Jack");
break;
case 12:
strcpy_s(numstr,"Queen");
break;
case 13:
strcpy_s(numstr,"King");
break;
default:
_itoa(cardnum,numstr,10);
break;
}
switch(suit){
case 1:
strcpy_s(suitstr, "Hearts");
break;
case 2:
strcpy_s(suitstr, "Clubs");
break;
case 3:
strcpy_s(suitstr, "Spades");
break;
case 4:
strcpy_s(suitstr, "Diamonds");
break;
}
strcat_s(str,numstr);
strcat_s(str,conststr);
strcat_s(str,suitstr);
char *s;
s = str;
cout << s << '\n';
return s;
}
int _tmain(int argc, _TCHAR* argv[])
{
card c(1,1);
char *s = c.toString();
cout << *s << '\n';
cout << s << '\n';
return 0;
}
|