// abstraction for a lotto system
// where the only game is the 6/55 lotto
// keeps track of revenues generated by the system
class lotto
{
public:
lotto(long int population, double percent_gambling, long int init_seed, long int price);
// population: 101833938
// percent_gambling: [31,100],
// base percentage of population
// that would usually bet
// init_seed: 108000000
// price: 20
// construct a 6/55 lotto system with gamblers being some percentage
// percent_gambling out of a total population
// e.g. population might be 85000000 (85 million) and
// percent_gambling may be 10.5 meaning 10.5 percent of 85 million
// would probably gamble on lotto initially (more might be induced
// to gamble if the prize money becomes bigger)
// main purpose of this class is to simulate revenue generation
// in a lotto system
// init_seed is the prize money for the first draw; the prize gets
// larger in a succeeding draw if no ticket wins; otherwise the
// prize reverts to some init_seed
void simulate(int n);
// simulate n draws of a lotto system;
// for each draw:
// anounce the jackpot prize
// generate a winning combination
// generate a random number indicating the number of bets
// that would be placed, depending on population,
// percent_gambling, the prize of the jackpot
// +/- some random number to incorporate some variability on the
// number of bets generated
// generate random lotto tickets and determine number of winners
// disclose the winning combination
// depending on number of winners, announce how much
// each winner receives, new value of jackpot prize,
// revenue generated, total revenue generated
// since start of simulation, other revenue-related computations
// add other functions as needed
private:
// add items as needed
};
// abstraction for a lotto combination
class lotto_ticket
{
public:
lotto_ticket();
// default constructor, constructs a random lotto ticket
void randomize(); // generates new random values for a lotto ticket
int at(int n); //returns ticket entry n, where n is in [1,6]
// returns 0 for other (invalid) n
// add items as needed
private:
// add items as needed
};
bool operator==(lotto_ticket a, lotto_ticket b);
// returns true if lotto ticket a is the same as lotto ticket b
// returns false otherwise
// usage: lotto_ticket a; lotto_ticket b;
// ... if (a == b) ...
#endif
lotto.cpp
#include "lotto.h"
// implement member functions of classes lotto and
// lotto_ticket in this file
lotto::lotto(long int population, double percent_gambling,
long int init_seed, long int price)
{
// code for constructor
}
//...
//allows comparison of two lotto tickets
// assuming at() is implemented properly
// and ticket entries are sorted
bool operator==(lotto_ticket a, lotto_ticket b)
{
for (int i=1; i<=6; i++)
{
if (! (a.at(i) == b.at(i)) )
return false;
}
//else
return true;
}
apparently we have exactly the same project. so, hi possible classmate of mine :) so uhh i'll try to help but i won't give you the answers directly.
didn't actually use the bool operator so i can't help you there
for the n draws, just make the "void lotto_ticket::randomize () {__};" one first. I suggest using the code used in shuffling cards like this one: http://www.fredosaurus.com/notes-cpp/misc/random-shuffle.html
just do some adjustments to it, an array with the numbers 1-55 instead of 1-52, take out the print part and add a 'for' statement to make another array with 6 digits containing the first 6 digits from that previous 55 numbered array.
do this unless if you're able to generate 6 random numbers which doesn't repeat any of the random numbers.
then after that, just run the randomize () through void lotto_ticket::generate (int x) {__}; which would loop it up to how many (or x) random lotto tickets you would want.
then you're now able to generate tickets, though you'd still have to find out how to actually run them :))