Lottery
Objective
1. To review reading from a file.
2. To use records (an instance of a struct)
3. To create an array dynamically. (array of structs)
4. To use enumerated types in a useful manner.
The Problem
You are hired by the state of Florida to decide who gets winnings for the Florida Lottery. The state has a system that automatically creates a file that contains the name of each ticket purchaser along with the combination of 6 distinct numbers picked by that person. Your job is to use this file in determining everyone’s winnings. In particular, here is the payout for matching a certain number of values:
Numbers Matched Winnings
3 $10
4 $100
5 $10000
6 $1000000
Your program will ask the user for an input file with the data for the ticket purchases. Then your program will ask the user for the winning combination of numbers. (When playing the Florida lottery, you must pick 6 distinct numbers from the set {1,2,3,…,52,53}.) So 53 is the highest possible number. The user MUST enter these numbers in ascending order. Once these have been entered, your program should print out the names of all the winners, along with how much money they have won. You are guaranteed that each person playing the lottery has bought EXACTLY one ticket and is listed once in the file.
In your implementation please adhere to the following guidelines:
1) Use a record to store information about each ticket.
2) Dynamically allocate an array to store all the ticket information based on the first number in the file.
3) Use an enumerated type for the four possible winning values.
References
Textbook: Chapter 2, 3
Input File Format
The input file your program will take in will have the following format:
The first line will contain a single integer n, the total number of tickets bought.
The next 2n lines will contain information about each ticket bought. The information for a single ticket will be on two lines. The first of the two lines will contain the last name of the ticket buyer, followed by a space, followed by the first name of the ticket buyer. Both the first and last name are guaranteed to be 19 characters or less. The following line will contain the six integers chosen by that buyer all in ascending order separated by spaces.
Here is a sample file, input.txt:
5
Llewellyn Mark
1 15 19 26 33 46
Young Brian
17 19 33 34 46 47
Cazalas Jonathan
1 4 9 16 25 36
Siu Max
17 19 34 46 47 48
Balci Murat
5 10 17 19 34 47
User Input Specification
1. The file name entered will be valid.
2. The winning lottery numbers will be valid and entered in ascending order.
Output Specification
Your output should contain one winner per line. Each line of output should be of the following format:
First Last matched X numbers and won $Y.
where First is the first name of the winner, Last is the last name of the winner, X is the number of winning numbers the player picked correctly, and Y is the prize money won.
Your program MUST adhere to this EXACT format (spacing capitalization, use of dollar signs, periods, punctuation, etc). The graders will use very large input files, resulting in very large output files. As such, the graders will use text comparison programs to compare your output to the correct output. If, for example, you have two spaces between First and Last instead of one space, this will show up as an error even through you may have the program correct. You WILL get points off if this is the case, which is why this is being explained in detail.
Again, your output MUST ADHERE EXACTLY to the line shown above.
Output Samples
Here is one sample output of running the program. Note that this is NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given. The user input is given in italics while the program output is in bold. (Note: The following output is based upon the sample input file shown above.)
Enter the name of the file with the ticket data.
input.txt
Enter the winning Lottery numbers
17 19 33 34 46 47
Mark Llewellyn matched 3 numbers and won $10.
Brian Young matched 6 numbers and won $1000000.
Max Siu matched 5 numbers and won $10000.
Murat Balci matched 4 numbers and won $100.
Grading Details
Your program will be graded upon the following criteria:
1) Adhering to the implementation specifications listed on the first page.
2) Your algorithmic design.
3) Correctness.
4) Use of Enumerated types for the structs
5) The frequency and utility of the comments in the code, as well as the use of white space for easy readability. (We’re not kidding here. If your code is poorly commented and spaced and works perfectly, you could earn as low as 80-85% on it.)
6) Compatibility to Dev C++. (If your program does not compile in Dev C++, you will get a sizable deduction from your grade.)
7) Your output MUST adhere to the EXACT FORMAT shown in the
Note: There is a more efficient way to determine the number of matching tickets compared to the straightforward method. No credit will be taken off if you don’t discover this method, but please do try to look for an efficient solution to this part of the problem.
Restrictions
Name the file you create and turn in lottery.c. Although you may use other compilers, your program must compile and run using Dev C++. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. You should also include comments throughout your code, when appropriate.
Deliverables
A single source file named lottery.c