Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. // [ub] C standard library headers in C++ are in the pattern of <c[library-name]> instead of <[library-name].h>
  2. // stdlib.h -> cstdlib, stdio.h -> cstdio, etc.
  3.  
  4. #include <functional>
  5. #include <iostream>
  6. #include <random> // [ub] Using C++ random instead of old school C random
  7. #include <string>
  8.  
  9. // [ub] Try not to import entire namespaces if you can get away with it (just specific things you're using)
  10. using std::cout;
  11. using std::endl;
  12.  
  13. class menstats { // [ub] You could call this MentalStats or something... it's 2019, we're not limited to 80 character line lengths anymore ;)
  14.  
  15.     //data for mental ability
  16. public:
  17.     // [ub] Is there a good reason for these to be publicly mutable? Also naming comment above applies here.
  18.     int perce; //oblivious / keen eyed
  19.     int spati; //bad spatial reasoning / good spatial reasoning
  20.     int intel; //bad patern recog / good patern recog
  21.  
  22.     menstats(const std::function<int(void)> &randomizer) {
  23.         perce = randomizer();
  24.         spati = randomizer();
  25.         intel = randomizer();
  26.     }
  27.  
  28.     menstats (const std::function<int(void)> &fuzzer, const menstats &a, const menstats &b) {
  29.         perce = (((a.perce + b.perce) / 2) + fuzzer());
  30.         spati = (((a.spati + b.spati) / 2) + fuzzer());
  31.         intel = (((a.intel + b.intel) / 2) + fuzzer());
  32.     }
  33. };
  34.  
  35. int main() {
  36.     std::random_device device;
  37.     std::default_random_engine generator{device()};
  38.  
  39.     std::uniform_int_distribution<int> distribution(1, 10);
  40.     auto randomizer = std::bind(distribution, generator);
  41.  
  42.     std::uniform_int_distribution<int> fuzzyDistribution(0, 3);
  43.     auto fuzzer = std::bind(fuzzyDistribution, generator);
  44.    
  45.     menstats one(randomizer);
  46.     menstats two(randomizer);
  47.     menstats three(fuzzer, one, two);
  48.  
  49.     cout << one.perce << endl;
  50.     cout << one.spati << endl;
  51.     cout << one.intel << endl;
  52.     cout << two.perce << endl;
  53.     cout << two.spati << endl;
  54.     cout << two.intel << endl;
  55.     cout << three.perce << endl;
  56.     cout << three.spati << endl;
  57.     cout << three.intel << endl;
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement