Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************
- * *
- * Program: (Duck Hunt) *
- * Program ID: (duck_hunt.cpp) *
- * Programmed by: (Fuji) *
- * Date Completed: (10/25/11) *
- * *
- ******************************************************************/
- /******************************************************************
- * C O M P I L E R D I R E C T I V E S *
- ******************************************************************/
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cmath>
- #include <time.h>
- /******************************************************************
- * G L O B A L D E C L A R A T I O N S *
- ******************************************************************/
- using namespace std;
- const int AMT_BROTHERS = 10;
- const int AMT_DUCKS = 10;
- const int ACCURACY_NORM = 100;
- const int TRIALS = 10;
- const string first_names[] = { "Alan","Alex","Alexi","Barry","Burt","Carry","Chad","Danny","Dan","Devin","Derrick",
- "Evan","Eric","Fenton","Gerry","Gerald","Harry","Harold","Ian","Jerry","Jimmy","Jim",
- "John","Johnny","Kevin","Kyle","Larry","Lawrence","Manny","Manfred","Mark","Marcus",
- "Nick","Nicholas","Odie","Obadiah","Perry","Quinby","Quinn","Ryan","Richard","Richie",
- "Sam","Samuel","Steven","Steve","Stephan","Tom","Thomas","Tim","Timmy","Timothy","Uri"
- "Ulrich","Vlad","Vladamir","Vick","Winston","Xavier","Xander","Zib","Zach","Zeon"};
- const string last_names[] = { "Anderson","Andrews","Burnside","Burton","Berry","Carson","Carry","D'amico",
- "Darrow","Dusseldorf","Edwards","Ericson","Fitzgerald","Finkle","Garrison",
- "Harrison","Hickley","Iams","Ice","Johnson","Jackson","Kelly","Kerry","Leeuwenhoek",
- "Larry","Mason","MacIntosh","Nelly","Nancy","Osborn","Olson","Parson","Pits","Quayle",
- "Quixote","Quigley","Richards","Rutz","Samson","Saturday","Trainsbury","Travis",
- "Uri","Valentine","Wendick","Wick","Xerxes","Xander","Zebra","Z"};
- /******************************************************************
- * B R O T H E R *
- ******************************************************************/
- class brother
- {
- private:
- int accuracy;
- int deadDuck;
- string first_name;
- string last_name;
- string name;
- public:
- brother::brother()
- {
- }
- void brother::chooseName()
- {
- int rand_first;
- int rand_last;
- rand_first = rand() % 62;
- rand_last = rand() % 48;
- first_name = first_names[rand_first];
- last_name = last_names[rand_last];
- name = first_name + " " + last_name;
- }
- void brother::setAccuracy(int skill)
- {
- accuracy = skill;
- }
- void brother::shootDuck()
- {
- int chance;
- chance = rand() % 100;
- if(chance <= accuracy)
- {
- deadDuck = rand() % AMT_DUCKS;
- }
- else
- {
- deadDuck = -1;
- }
- }
- string brother::getName()
- {
- return name;
- }
- int brother::getAccuracy()
- {
- return accuracy;
- }
- int brother::getDuck()
- {
- return deadDuck;
- }
- };
- /******************************************************************
- * D U C K *
- ******************************************************************/
- class duck
- {
- private:
- int number;
- bool shot;
- public:
- duck::duck()
- {
- bool shot = false;
- }
- void duck::setNumber(int num)
- {
- number = num;
- }
- void duck::shoot()
- {
- shot = true;
- }
- void duck::unShoot()
- {
- shot = false;
- }
- int duck::getNumber()
- {
- return number;
- }
- bool duck::getShot()
- {
- return shot;
- }
- };
- /******************************************************************
- * M A I N *
- ******************************************************************/
- void main()
- {
- srand ( time(NULL) );
- brother *frat = new brother[AMT_BROTHERS];
- duck *quack = new duck[AMT_DUCKS];
- int survivors;
- float total_survivors = 0.0;
- float mean_survivors;
- for(int i = 0; i < AMT_DUCKS; i++)
- {
- quack[i].setNumber(i);
- }
- for(int j = 0; j < TRIALS; j++)
- {
- survivors = 0;
- cout << "+----------------------------------+" << endl;
- for(int i = 0; i < AMT_BROTHERS; i++)
- {
- string line;
- frat[i].chooseName();
- frat[i].setAccuracy(ACCURACY_NORM);
- frat[i].shootDuck();
- line = (frat[i].getName() + " : ");
- cout << setw(20) << line;
- cout << frat[i].getDuck();
- cout << endl;
- quack[frat[i].getDuck()].shoot();
- }
- cout << "+----------------------------------+" << endl;
- for(int i = 0; i < AMT_DUCKS; i++)
- {
- string line;
- line = " Duck : ";
- cout << setw(12) << quack[i].getNumber();
- cout << line;
- cout << quack[i].getShot();
- cout << endl;
- if(quack[i].getShot() != true)
- {
- survivors++;
- }
- else
- {
- quack[i].unShoot();
- }
- }
- cout << "+----------------------------------+" << endl;
- cout << "Surviving Ducks: " << survivors << endl;
- total_survivors += survivors;
- cout << "+----------------------------------+" << endl;
- cout << "Total Surviving Ducks: " << total_survivors << endl;
- cout << endl;
- }
- mean_survivors = total_survivors / TRIALS;
- cout << "+----------------------------------+" << endl;
- cout << "Mean Surviving Ducks: " << mean_survivors << endl;
- system("pause");
- }
Add Comment
Please, Sign In to add comment