Advertisement
silentkiler029

Question-02-a

Nov 1st, 2021
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. // Question - 02
  2.  
  3. #include <bits.stdc++.h>
  4. using namespace std;
  5.  
  6. // --- ( a )---
  7. class Dice {
  8. private:
  9.     double ara[7];
  10. public:
  11.     Dice() {
  12.         for( int i = 0; i < 7; i++ ) {
  13.             ara[i] = 0;
  14.         }
  15.     }
  16.     void roll() {
  17.         srand(time(0));
  18.         int d = 1 + rand() % 6;
  19.         ara[d] += 1.00;
  20.     }
  21.  
  22.     class Experiment {
  23.     public:
  24.         bool isFair() {
  25.             double tot = 0;
  26.             for( int i = 1; i < 7; i++ ) {
  27.                 tot += ara[i];
  28.             }
  29.             double percentage[7], minn = 101.00, maxx = 0.00;
  30.             for( int i = 1; i < 7; i++ ) {
  31.                 percentage[i] = ( ara[i] / tot ) * 100;
  32.                 if( minn > percentage[i] ) {
  33.                     minn = percentage[i];
  34.                 }
  35.                 if( maxx < percentage[i] ) {
  36.                     maxx = percentage[i];
  37.                 }
  38.             }
  39.             if( maxx - minn >= 10.00 ) {
  40.                 return false;
  41.             }
  42.             return true;
  43.         }
  44.     }
  45.  
  46.     class Program {
  47.     private:
  48.         int numberOfRolls;
  49.  
  50.     public:
  51.         Program( int rolls ) {
  52.             numberOfRolls = rolls;
  53.         }
  54.         int getRolls() {
  55.             return numberOfRolls;
  56.         }
  57.         void setRoll( int roll ) {
  58.             numberOfRolls = rolls;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement