Advertisement
kubbur

Untitled

Feb 1st, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // Kristófer Smári Leifsson
  2.  
  3.  
  4. // Forritun 01FEB Pre-Lab.cpp : Defines the entry point for the console application.
  5. //
  6.  
  7.  
  8. #include "stdafx.h"
  9. #include<iostream>
  10. #include<time.h>
  11. #include<string>
  12. using namespace std;
  13.  
  14. class dice
  15. {
  16. public:
  17.  
  18. virtual void roll()
  19. {
  20. cout << "ERROR" << endl;
  21. }
  22.  
  23. protected:
  24. int tvaerhlidar = rand() % 2 + 1;
  25. int rps = rand() % 3 + 1; //
  26. int sexhlidar = rand() % 6 + 1;
  27. };
  28.  
  29.  
  30. class crps : public dice
  31. {
  32. public:
  33. void roll()
  34. {
  35. if (rps == 1)
  36. cout << "rock" << endl;
  37. else if (rps == 2)
  38. cout << "paper" << endl;
  39. else if (rps == 3)
  40. cout << "sissors" << endl;
  41. }
  42. };
  43.  
  44.  
  45. class ctvaerhlidar : public dice
  46. {
  47. public:
  48. void roll()
  49. {
  50. if (tvaerhlidar == 1)
  51. {
  52. cout << "Heads" << endl;
  53. }
  54. else if (tvaerhlidar == 2)
  55. {
  56. cout << "Tails" << endl;
  57. }
  58. }
  59. };
  60.  
  61.  
  62. class csexhlidar : public dice
  63. {
  64. public:
  65. void roll()
  66. {
  67. cout << sexhlidar << endl;
  68. }
  69. };
  70.  
  71. void prenta(dice& throwing, dice& mix, dice& display)
  72. {
  73.  
  74. for (int i = 1; i < 11; i++)
  75. {
  76. int sinnum = rand() % 3 + 1;
  77.  
  78. if (sinnum == 1)
  79. {
  80. throwing.roll();
  81. }
  82. else if (sinnum == 2)
  83. {
  84. mix.roll();
  85. }
  86. else if (sinnum == 3)
  87. {
  88. display.roll();
  89. }
  90.  
  91. }
  92. }
  93.  
  94. int main()
  95. {
  96. system("chcp 1252 > nul");
  97. srand(time(NULL));
  98.  
  99. dice *ax, *bx, *cx;
  100. ctvaerhlidar a;
  101. crps b;
  102. csexhlidar c;
  103.  
  104. ax = &a;
  105. bx = &b;
  106. cx = &c;
  107.  
  108. prenta(*ax, *bx, *cx);
  109.  
  110. system("pause");
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement