Professional Documents
Culture Documents
General Instructions
In this assignment, you will be implementing the ‘Lotto’ game in an object-oriented
manner. This program would involve some basic manipulation of numbers, randomnumber
generation and writing to files. The driver program is given to you and you are NOT
allowed to change it. Hence, the obvious overloaded operators will be output << which
need to be implemented.
Specific Instructions
This assignment should be written as a modular C++ program. You will develop a class
(module) called LottoTicket, with header (.h) and implementation (.cpp) files. The main
program should be in its own module and is given to you.
This is a 5-player game. The user inputs a minimum(min) value, maximum(max) value,
number of rounds(r) to be played. This information is used to generate a LottoTicket. A
LottoTicket has 15 slots, which has to be randomly filled between the min and max
value(inclusive). Once all tickets are generated, the game starts and will play ‘r’ rounds.
For each round, a random number between min and max(inclusive) is generated and this
value is searched in each ticket to see if it is found in any one of the 15 slots. Please note,
that if a number is repeated in a ticket, then only one occurrence of the number is
considered as found.
The winner is decided by the first player who has all 15 slots revealed/found before the ‘r’
rounds are completed, else the game is considered a draw. You are required to print the
Ticket details along with the status of each round to both the console and an output file.
Please note that a properly seeded random number generator will ensure different results
for each run.
Driver program:
int main() {
int num_of_players = 5;
LottoTicket players[5];
int min = 0;
int max = 0;
int max_rounds = 0;
int winner = -1;
bool gameover;
string filename = "output.txt";
ofstream fout;
srand(time(NULL));
int i = 0;
while(i != num_of_players) {
LottoTicket player1(i);
player1.generateLotto(min,max);
players[i] = player1;
i++;
}
i = 0;
cout<<"\n";
cout<<" ";
cout<<"\nGame is starting"<<endl;
cout<<"Round# \tLotto\tP#0\tP#1\tP#2\tP#3\tP#4"<<endl;
fout<<"\n";
fout<<" -";
fout<<"\nGame is starting"<<endl;
fout<<"Round# \tLotto\tP#0\tP#1\tP#2\tP#3\tP#4"<<endl;
for(int j = 0; j < max_rounds; j++) {
int current_lotto = generateRandom(min, max);
cout<<j<<"\t"<<current_lotto<<"\t";
fout<<j<<"\t"<<current_lotto<<"\t";
for(LottoTicket &lotto: players) {
gameover = lotto.play(current_lotto);
cout<<lotto.getLottosWonCount()<<"\t";
fout<<lotto.getLottosWonCount()<<"\t";
if(gameover) {
winner = lotto.getId();
break;
}
}
cout<<endl;
fout<<endl;
if(gameover) {
break;
}
}
cout<<" ";
cout<<"\n\tRESULT: \t";
fout<<" ";
fout<<"\n\tRESULT: \t";
if(winner >= 0) {
cout<<"Winner is: Player "<<winner<<endl;
fout<<"Winner is: Player "<<winner<<endl;
} else {
cout<<"This game is a draw"<<endl;
fout<<"This game is a draw"<<endl;
}
return 0;
}
Output: