fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include "Card.h"
  4.  
  5. using std::cout;
  6. using std::endl;
  7.  
  8.  
  9. /* make_card
  10.  *
  11.  * Allocate space for AND initialize the values for a single card
  12.  */
  13.  
  14. Card::Card(int sui, int val)
  15. {
  16. suit = sui;
  17. value = val;
  18. }
  19.  
  20. int Card::get_suit() const
  21. {
  22. return suit;
  23. }
  24.  
  25. int Card::get_value() const
  26. {
  27. return value;
  28. }
  29.  
  30. /* compare
  31.  *
  32.  * Compare two cards. The way we compare cards is to first look at the
  33.  * value. If the values are different, then the card with the higher value
  34.  * is higher. If the values are the same, then we check the suit. The vard
  35.  * with a suit with a higher value (0-3) is higher.
  36.  *
  37.  * The compare result is -1, 0, or 1. If c1 < c2, then return -1. If
  38.  * c1 == c2, then return 0. If c1 > c2, then return 1.
  39.  */
  40.  
  41. int Card::compare(const Card& c) const
  42. {
  43. if (value == c.get_value())
  44. {
  45. if (suit > c.get_suit())
  46. return 1;
  47. else if (suit < c.get_suit())
  48. return -1;
  49. else
  50. return 0;
  51. }
  52. else if (c.get_value() > value)
  53. return -1;
  54. else
  55. return 1;
  56. }
  57.  
  58. void Card::print_card()const
  59. {
  60. char suitchars[] = "CDHS";
  61. char valuechars[] = "WA23456789TJQK";
  62.  
  63. if ((suit < 0) || (suit > 3))
  64. /*printf("Invalid suit: %d\n",suit);*/
  65. cout << "Invalid suit: " << get_suit() <<endl;
  66. else if ((value < 0) || (value > 13))
  67. /*printf("Invalid value: %d\n",value);*/
  68. cout << "Invalid value: " << get_value() << endl;
  69. else
  70. cout << suitchars[get_suit()] << " "<< valuechars[get_value()] << " " ;
  71. }
  72.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:18: fatal error: Card.h: No such file or directory
 #include "Card.h"
                  ^
compilation terminated.
stdout
Standard output is empty