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 the 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. Lottery. In this assignment you are to code a program that selects 10 random non-repeating positive numbers (the lottery numbers), takes a single input from the user and checks the input with the ten lottery numbers. The user wins if her input matches one of 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_Lottery. Declare an array wins of 10 integer elements.

    Define the following functions:

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

      main(){
          declare array and other variables
      
          initialize(...) // fill array with -1
          draw(...)       // select 10 non-repeating random numbers
          entry(...)      // get user input
          use check () to compare user input against lottery numbers
          and output whether user won
          printOut(...)   // outputs seleced 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.

    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.

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.