Lab Assignment 6

Call-by-Reference, Arrays

There are two problems for this lab. Create multiple files for these two problems and provide a make file for each named makefile1 and makefile2 respectively.


1.
Find Number. Declare an array of 10 integer elements. Use srand, rand and ctime functions to generate random numbers from 1 to 99 and fill the array. The numbers may repeat. Print the selected numbers.

Ask the user to input a number between 1-99. Check to see if the number matches any of the selected numbers. Print the user input number and whether there is or is not a match. Allow the user to repeat the search until a 0 is input.


2.
Lottery Checker. Study debugging with arrays in functions Modify the above program as follows.
Declare an array
wins of 10 integer elements. Define a function draw that takes the array wins as a parameter and fills it with 10 integers whose values are from 1 to 100. The numbers should not repeat this time.

Hint: Initialize the array with zeroes- a number that does not appear in the drawing. This allows you to search the array even if some elements are still not filled. Then, for each selected new random number, before entering it into the array wins, call the function check described below to check to make sure that the new number is not already in the array. If it is already there, select another number. Otherwise, put it in the array in the next open position.

Define a function entry that asks the user to enter a single number from 1 to 100. This function should take the user entry as a call-by-reference parameter (which will allow entry to be called as below, entry(...)). Define a function check that takes a number input and the array wins as parameters and returns the index of the array element that matches the input number or zero if none of the elements do.

Create another function printOut that prints the selected numbers, user input, and whether the user won the lottery by finding their number in the array. The general outline of your function main() should be as follows:

main(){
// array and other variable declarations

draw(...)
entry(...)
check(...)
printOut(...)

}

Assume this program wil be rerun if more than one lottery is to be run.

Create a script file, lab6_script, showing how to display array variables in a function and change one of them. Submit with your files.


Make sure your programs adhere to proper programming style. Submit your projects to the subversion repository. Do not forget to verify your submission on the web.