Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <vector>
  6. #include <vld.h>
  7. //#include "Fraction.hpp"
  8. using namespace std;
  9.  
  10. //class Fraction {
  11. //public:
  12. //  Fraction(int n = 0, int d = 1) { num = n; dem = d; }
  13. //  void display() { cout << "The entered fraction is " << num << "/" << dem; }
  14. //
  15. //  int num;
  16. //  int dem;
  17. //  double value() { return num / dem; }
  18. //};
  19. //
  20. //class FracList {
  21. //public:
  22. //  void displaylist();
  23. //
  24. //  vector<Fraction> list;
  25. //  int countsize = 0;
  26. //  int limit;
  27. //};
  28. //
  29. //
  30. //
  31. //int main() {
  32. //  FracList f;
  33. //  Fraction temp;
  34. //
  35. //  cout << "Enter a positive int: ";
  36. //  cin >> f.limit;
  37. //
  38. //  cout << "Enter a fraction: ";
  39. //  cin >> temp.num >> temp.dem;
  40. //  temp.display();
  41. //
  42. //  system("pause");
  43. //  return 0;
  44. //}
  45.  
  46. class GuessAWord {
  47. private:
  48.   char answer[9];
  49.   char camo[9] = "********";
  50.   int liter = 0;
  51.  
  52. public:
  53.   void delit() { liter -= 1; }
  54.   GuessAWord(char a[9] = "starline", char b[9] = "solomida", char c[9] = "skillful", char d[9] = "holycrab", char e[9] = "triggere") {
  55.     srand(time(NULL));
  56.     int sel = rand() % 5;
  57.     switch (sel) {
  58.     case 0:
  59.       strcpy(answer, a);
  60.       break;
  61.     case 1:
  62.       strcpy(answer, b);
  63.       break;
  64.     case 2:
  65.       strcpy(answer, c);
  66.       break;
  67.     case 3:
  68.       strcpy(answer, d);
  69.       break;
  70.     case 4:
  71.       strcpy(answer, e);
  72.       break;
  73.     }
  74.   }
  75.  
  76.   void play() {
  77.     char putin;
  78.  
  79.     while (1) {
  80.       try {
  81.         cout << "Guess a letter in the secret word: " << camo << endl;
  82.         cin >> putin;
  83.         bool sw = false;
  84.  
  85.         for (int i = 0; i < 8; i++) {
  86.           if (putin == answer[i]) {
  87.             camo[i] = putin;
  88.             sw = true;
  89.           }
  90.         }
  91.         if (sw == false)
  92.           throw "Sorry - " + putin + "is not in the word";
  93.         liter += 1;
  94.         if (strcmp(camo, answer) == 0)
  95.           break;
  96.       }
  97.       catch (const char* msg) {
  98.         cerr << msg << endl;
  99.       }
  100.     }
  101.  
  102.  
  103.     cout << "Congratulation! You guess the word literary in " << liter << "tries." << endl;
  104.     cout << "Do you want to play again? Y or N: ";
  105.     cin >> putin;
  106.     if (putin == 'y')
  107.     {
  108.       GuessAWord;
  109.       strcpy(camo, "********");
  110.       liter = 0;
  111.       play();
  112.     }
  113.   }
  114. };
  115.  
  116. class NonLetterException :public invalid_argument {
  117. public:
  118.   NonLetterException(GuessAWord game, string msg) : invalid_argument(msg), val(game) { ; }
  119.   GuessAWord val;
  120. };
  121.  
  122. void main() {
  123.   GuessAWord game;
  124.   game.play();
  125.   system("pause");
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement