fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. #include <map>
  6. using namespace std;
  7.  
  8.  
  9.  
  10. class Card {
  11. public:
  12. Card(int value, string suit){
  13. this -> value = value;
  14. this -> suit = suit; //5-1
  15. }
  16. int getS() /*getScore*/{
  17. map<string, int>suitCode = {{"spade",4},{"heart",3}, {"diamond",2}, {"club",1}};
  18. int score;
  19. score = value*10 +suitCode[suit]; // 5-2
  20. return score;
  21. }
  22. private:
  23. int value;
  24. string suit;
  25. };
  26. class Player{
  27. public:
  28. Player(){ }
  29. int getRank(){
  30. int rank, i;
  31. rank = 0;
  32. for(i=0; i<cards.size(); i++){
  33. rank += cards; //5-3
  34. }
  35. return rank;
  36. }
  37. void addCard(Card *card){
  38. cards.push_back(card);
  39. }
  40. private:
  41. vector<Card*>cards;
  42. };
  43.  
  44. class PokerGame{
  45. public:
  46. PokerGame(){ }
  47. void deal(vector<Card*> inCards){
  48. int ();
  49. int i;
  50. for (i=0; i<inCards.size(); i+=2){
  51. human inCards[i]; //5-4
  52. computer inCards[++i]; //5-5
  53. }
  54. }
  55. string play(){
  56. stringstream ss1, ss2;
  57. string s1, s2, result;
  58. ss1<< human -> getRank(); ss1>>s1;
  59. ss2<< computer->getRank(); ss2>>s2;
  60. result = "Player=" + s1 +",Computer="+ s2;
  61. if (s1>s2) //5-6
  62. result +=", Player Win. \n";
  63. else if (s1<s2)
  64. result +=", Computer Win. \n";
  65. else result += ", Push.\n";
  66. return result;
  67. }
  68. private:
  69. Player *human,*computer;
  70. void init(){
  71. human = new Player();
  72. computer = new Player();
  73. }
  74. };
  75.  
  76. void testPokerGame(){
  77. PokerGame game;
  78. vector<Card*>inCards1 = {new Card(5,"spade"),new Card(6,"spade")};
  79. vector<Card*>inCards2 = {new Card(5,"spade"),new Card(6,"spade"),new Card(5,"heart"),new Card(6,"heart")};
  80. vector<Card*>inCards3 = {new Card(9,"spade"),new Card(9,"club"),new Card(8,"diamond"),new Card(8,"heart")};
  81. game.deal(inCards1);
  82. cout<<game.play();
  83. game.deal(inCards2);
  84. cout<<game.play();
  85. game.deal(inCards3);
  86. cout<<game.play();
  87. }
  88.  
  89. int main(){
  90. testPokerGame();
  91. return 0;
  92. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘int Player::getRank()’:
prog.cpp:33:10: error: no match for ‘operator+=’ (operand types are ‘int’ and ‘std::vector<Card*>’)
     rank += cards; //5-3
     ~~~~~^~~~~~~~
prog.cpp: In member function ‘void PokerGame::deal(std::vector<Card*>)’:
prog.cpp:51:10: error: expected ‘;’ before ‘inCards’
     human inCards[i]; //5-4
          ^~~~~~~~
          ;
prog.cpp:52:13: error: expected ‘;’ before ‘inCards’
     computer inCards[++i]; //5-5
             ^~~~~~~~
             ;
stdout
Standard output is empty