Advertisement
pichumy

Untitled

Jan 27th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include "Card.h"
  4.  
  5. Card::Card(int suit, int value)
  6. {
  7. suit = suit;
  8. value = value;
  9. }
  10.  
  11. int Card::get_suit() const
  12. {
  13. return suit;
  14. }
  15. int Card::get_value() const
  16. {
  17. return value;
  18. }
  19.  
  20. int Card::compare(const Card& c) const
  21. {
  22. if(value != c.value)
  23. {
  24. if(value > c.value) return 1;
  25. else return -1;
  26. }
  27. else if(suit != c.suit)
  28. {
  29. if(suit > c.suit) return 1;
  30. else return -1;
  31. }
  32. return 0;
  33. }
  34.  
  35.  
  36. void Card::print_card(FILE *fp) const
  37. {
  38. const char* suitchars = "CDHS";
  39. const char* suitvalues = "WA23456789TJQK";
  40. if ((suit < 0) || (suit > 3))
  41. fprintf(fp, "Invalid suit: %d\n",suit);
  42. else if ((value < 0) || (value > 13))
  43. fprintf(fp, "Invalid value: %d\n",value);
  44.  
  45. fprintf(fp, "%c %c ", suitchars[suit], suitvalues[value]);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement