Guest User

Untitled

a guest
Apr 19th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. /******************************************************************
  2. * *
  3. * Program: (Duck Hunt) *
  4. * Program ID: (duck_hunt.cpp) *
  5. * Programmed by: (Fuji) *
  6. * Date Completed: (10/25/11) *
  7. * *
  8. ******************************************************************/
  9.  
  10. /******************************************************************
  11. * C O M P I L E R D I R E C T I V E S *
  12. ******************************************************************/
  13. #include "stdafx.h"
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <string>
  17. #include <cmath>
  18. #include <time.h>
  19.  
  20. /******************************************************************
  21. * G L O B A L D E C L A R A T I O N S *
  22. ******************************************************************/
  23. using namespace std;
  24.  
  25. const int AMT_BROTHERS = 10;
  26. const int AMT_DUCKS = 10;
  27. const int ACCURACY_NORM = 100;
  28. const int TRIALS = 10;
  29.  
  30. const string first_names[] = { "Alan","Alex","Alexi","Barry","Burt","Carry","Chad","Danny","Dan","Devin","Derrick",
  31. "Evan","Eric","Fenton","Gerry","Gerald","Harry","Harold","Ian","Jerry","Jimmy","Jim",
  32. "John","Johnny","Kevin","Kyle","Larry","Lawrence","Manny","Manfred","Mark","Marcus",
  33. "Nick","Nicholas","Odie","Obadiah","Perry","Quinby","Quinn","Ryan","Richard","Richie",
  34. "Sam","Samuel","Steven","Steve","Stephan","Tom","Thomas","Tim","Timmy","Timothy","Uri"
  35. "Ulrich","Vlad","Vladamir","Vick","Winston","Xavier","Xander","Zib","Zach","Zeon"};
  36.  
  37. const string last_names[] = { "Anderson","Andrews","Burnside","Burton","Berry","Carson","Carry","D'amico",
  38. "Darrow","Dusseldorf","Edwards","Ericson","Fitzgerald","Finkle","Garrison",
  39. "Harrison","Hickley","Iams","Ice","Johnson","Jackson","Kelly","Kerry","Leeuwenhoek",
  40. "Larry","Mason","MacIntosh","Nelly","Nancy","Osborn","Olson","Parson","Pits","Quayle",
  41. "Quixote","Quigley","Richards","Rutz","Samson","Saturday","Trainsbury","Travis",
  42. "Uri","Valentine","Wendick","Wick","Xerxes","Xander","Zebra","Z"};
  43.  
  44. /******************************************************************
  45. * B R O T H E R *
  46. ******************************************************************/
  47.  
  48. class brother
  49. {
  50. private:
  51. int accuracy;
  52. int deadDuck;
  53.  
  54. string first_name;
  55. string last_name;
  56. string name;
  57.  
  58. public:
  59. brother::brother()
  60. {
  61. }
  62.  
  63. void brother::chooseName()
  64. {
  65. int rand_first;
  66. int rand_last;
  67.  
  68. rand_first = rand() % 62;
  69. rand_last = rand() % 48;
  70.  
  71. first_name = first_names[rand_first];
  72. last_name = last_names[rand_last];
  73.  
  74. name = first_name + " " + last_name;
  75. }
  76.  
  77. void brother::setAccuracy(int skill)
  78. {
  79. accuracy = skill;
  80. }
  81.  
  82. void brother::shootDuck()
  83. {
  84. int chance;
  85.  
  86. chance = rand() % 100;
  87.  
  88. if(chance <= accuracy)
  89. {
  90. deadDuck = rand() % AMT_DUCKS;
  91. }
  92. else
  93. {
  94. deadDuck = -1;
  95. }
  96. }
  97.  
  98. string brother::getName()
  99. {
  100. return name;
  101. }
  102.  
  103. int brother::getAccuracy()
  104. {
  105. return accuracy;
  106. }
  107.  
  108. int brother::getDuck()
  109. {
  110. return deadDuck;
  111. }
  112.  
  113. };
  114.  
  115. /******************************************************************
  116. * D U C K *
  117. ******************************************************************/
  118.  
  119. class duck
  120. {
  121. private:
  122. int number;
  123. bool shot;
  124.  
  125. public:
  126. duck::duck()
  127. {
  128. bool shot = false;
  129. }
  130.  
  131. void duck::setNumber(int num)
  132. {
  133. number = num;
  134. }
  135.  
  136. void duck::shoot()
  137. {
  138. shot = true;
  139. }
  140.  
  141. void duck::unShoot()
  142. {
  143. shot = false;
  144. }
  145.  
  146. int duck::getNumber()
  147. {
  148. return number;
  149. }
  150.  
  151. bool duck::getShot()
  152. {
  153. return shot;
  154. }
  155. };
  156.  
  157. /******************************************************************
  158. * M A I N *
  159. ******************************************************************/
  160.  
  161. void main()
  162. {
  163. srand ( time(NULL) );
  164.  
  165. brother *frat = new brother[AMT_BROTHERS];
  166. duck *quack = new duck[AMT_DUCKS];
  167.  
  168. int survivors;
  169.  
  170. float total_survivors = 0.0;
  171. float mean_survivors;
  172.  
  173. for(int i = 0; i < AMT_DUCKS; i++)
  174. {
  175. quack[i].setNumber(i);
  176. }
  177.  
  178. for(int j = 0; j < TRIALS; j++)
  179. {
  180. survivors = 0;
  181.  
  182. cout << "+----------------------------------+" << endl;
  183.  
  184. for(int i = 0; i < AMT_BROTHERS; i++)
  185. {
  186. string line;
  187.  
  188. frat[i].chooseName();
  189. frat[i].setAccuracy(ACCURACY_NORM);
  190. frat[i].shootDuck();
  191.  
  192. line = (frat[i].getName() + " : ");
  193.  
  194. cout << setw(20) << line;
  195. cout << frat[i].getDuck();
  196. cout << endl;
  197.  
  198. quack[frat[i].getDuck()].shoot();
  199. }
  200.  
  201. cout << "+----------------------------------+" << endl;
  202.  
  203. for(int i = 0; i < AMT_DUCKS; i++)
  204. {
  205. string line;
  206.  
  207. line = " Duck : ";
  208.  
  209. cout << setw(12) << quack[i].getNumber();
  210. cout << line;
  211. cout << quack[i].getShot();
  212. cout << endl;
  213.  
  214. if(quack[i].getShot() != true)
  215. {
  216. survivors++;
  217. }
  218. else
  219. {
  220. quack[i].unShoot();
  221. }
  222. }
  223.  
  224. cout << "+----------------------------------+" << endl;
  225. cout << "Surviving Ducks: " << survivors << endl;
  226.  
  227. total_survivors += survivors;
  228.  
  229. cout << "+----------------------------------+" << endl;
  230. cout << "Total Surviving Ducks: " << total_survivors << endl;
  231. cout << endl;
  232. }
  233.  
  234. mean_survivors = total_survivors / TRIALS;
  235.  
  236. cout << "+----------------------------------+" << endl;
  237. cout << "Mean Surviving Ducks: " << mean_survivors << endl;
  238.  
  239. system("pause");
  240. }
Add Comment
Please, Sign In to add comment