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 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <vector>
#include <random>
using namespace std;
class money
{
private:
int value;
int uniqueID;
string name;
public:
money(int v, int id, const string& name)
: value(v), uniqueID(id), name(name) {}
int val() const { return value; }
};
class Me
{
private:
vector<money> myPocket;
public:
void put(const money& m)
{
myPocket.push_back(m);
std::cout << "Added " << m.val() << " to my pocket\n";
}
};
const money bills[4] = { money(1, 0, "one"), money(5, 0, "five"),
// what happened to 10?
money(20, 0, "twenty"), money(50, 0, "fifty") };
int main()
{
Me me;
random_device rd;
mt19937 eng(rd());
uniform_int_distribution<> d(0, 3);
for(int n = 0; n < 100; ++n)
me.put(bills[d(eng)]);
}
| |