-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbool_source.h
30 lines (27 loc) · 1.12 KB
/
bool_source.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*BOOL_SOURCE HEADER FILE
the bool_source class was soley created, in the context of HW2 assignment, to allow for the
implementation of a Query function. This function determines whether a student has arrived or not by using the
probabilty of a student arriving which the bool_source object was instantiated with. Note that rand() is
seeded in HW2.cpp*/
#ifndef BOOL_SOURCE_H
#define BOOL_SOURCE_H
#include <cassert>
#include <cstdlib>
//this class was created to implement a query function that uses the probability of a student arriving
//passed into sim function (in simulation()) to determine wehther a stduent has arrived or not. Use
//may be seen in simulation function.
class bool_source{
public:
bool_source(double p = 0.5) : prob_(p){
assert(p >= 0);//assert that passed in prob is greater than 0% and less than or equal to 100%
assert(p <= 1);
prob_ = p;
}
//member functions
bool query(){//determine whether a student arrived or not.
return (rand() < prob_ * RAND_MAX);//i don't even know how query() can access prob_
}
private:
double prob_;//probability passed into bool_source object
};
#endif