Call-by-Reference, Arrays

You are free to use a single or multiple files for this project. If you are putting all functions in a single file, make sure that more abstract functions are defined first.

  1. Mini-sort with functions. Create a project titled Lab6_Swap. Revisit this program from one of the earlier lab assignments that sorts three numbers in the increasing order. Modify it so that it invokes a function to swap the values of two variables. You should use the swapping function from this program. The pseudocde for the main() function is as follows:
          input three numbers
          if first number is greater than second 
              invoke the swap function to swap first and second numbers
          if first is greater than third 
              invoke the swap function to swap first and third numbers
          if second is greater than third
              invoke the swap function to swap second and third numbers
          output three sorted numbers
        
  2. Lucky Five. In this assignment you are to code a program that selects 10 random non-repeating positive numbers, inputs 5 numbers from the user and checks the input with the 10 lottery numbers. The lottery numbers range from 0 to 99. The user wins if at least one input number matches the lottery numbers.

    Study displaying arrays in functions described here. As you program your project, demonstrate to the lab instructor displaying an array passed to a function. Create a project titled Lab6_LuckyFive. Declare an array chosen of 10 integer elements.

    Define the following functions:

    The pseudocode your function main() should be as follows:

      main(){
          declare array and other variables
      
          assign(...) // fill array with -1
          draw(...)       // select 10 non-repeating random numbers
          iterate five times
                entry(...)      // get user input
                use check () to compare user input against lottery numbers
                if won state and quit
          printOut(...)   // outputs selected lottery numbers
      }
      

    Note: A program that processes each element of the array separately (i.e. accesses all 10 elements of the array for assignment or comparison outside a loop) is inefficient and will result in a poor grade. Likewise, processing each user entry outside a loop is inefficient.

    Note 2: For your project, you should either pass the array size (10) to the functions as a parameter or use a global constant to store it. Hard-coding the literal constant 10 in function definitions that receive the array as a parameter is poor style. It should be avoided.

Milestone: first assingment.

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.