Homework4

advertisement
CSC 125 Introduction to C++ Programming
Fall 2005
Homework 4
Due Date: November 16, 2005 at 2:00pm in class
Problem: Lottery Application
Write a program that simulates a lottery. The program should have an array of five
integers named lottery, and should generate a random number in the range of 0 through
36 for each element in the array. The user should enter five digits which should be stored
in an integer array named user. The program is to compare the corresponding elements in
the two arrays and keep a count of the digits that match. For example, the following
shows the lottery array and the user array with sample numbers stored in each, there are
three matching digits (element 1, 2 and 4).
7
Lottery array:
35
12
10
8
7
User array:
35
24
10
0
The program should display the random numbers stored in the lottery array and the
number of digits matching digits. If all of the digits match, display a message proclaiming
the user as a grand prize winner.
Requirement:
Please design a friendly interface for the lottery application, which make the user to feel
like buying a real lottery.
Your program should allow the user to repeat this game.
Your program should contain at least three functions. One is used to produce the random
numbers in lottery array. The second is to simulate the procedure of user’s buying lottery.
The third is used to compare the user array with lottery array. At least one function
should use arrays as parameters for the function.
Please using some examples to test your program.
Submission:
1. Print out of the program.
2. Sample runs (screen print outs)
3. A floppy disk (or CD or email to huiliu@missouristate.edu) holding two files:
asg4.cpp and asg4.exe.
It is better to upload your program to \\eccentric\Upload\CSC125\001.
If you determine to email your homework to me, please notice:
I wanna to receive a compressed file named as asg4.zip, which includes asg4.cpp and
asg4.exe.
The subject of the email is shown as “C++ homework4, from your full name”.
Note:
1. For all assignments, always use comments to explain your program.
2. Assignments need to be returned at the beginning of the lecture on the due date.
3. A late assignment will receive reduce credit of 10% for each 24-hour period
(including weekends and holidays) after the due dates. A late assignment will not be
accepted after that assignment has been graded and returned to the students unless
prior arrangements have been made with the instructor.
4. Assignments will generally be graded within one week. You will be notified
otherwise.
5. Programming assignments will be compiled and executed using Virtual C++ on the
machines in the departmental computer labs under the Window environment. Any
programming assignment that fails to do so will not be accepted.
Download