Lab 5

CS 1005, C-term 03

February 19, 2003

Problem

The goal of this lab is to give you practice in writing programs using 1-dimensional arrays and functions. You will also use the debugger to verify that your program works.

What you should do...

  1. Sign the attendance sheet.

  2. Write a program which asks the user to enter an integer in the range
     0 < n <= 20
    The program then reads in n integers and saves them in an array. You may assume that the number of elements in the array will not exceed 20. Name your program lab5.cxx.

  3. Compile and run your program. Your program doesn't produce any output, so it's hard to tell if it works correctly! Use the debugger to convince yourself that the program works. Here are some reminders about using the debugger:

  4. Once you're sure your program runs correctly, add a function that prints out a line of stars for every number in the array. If the first number in the array is 12, print 12 stars, and so on .... (Hint: you will need two for loops, one inside the other.)

    Be sure to pass the array to the function as a parameter. You should also pass the current size of the array as a parameter.

    Here is a sample execution...

    Input an integer between 1 and 20: 8
    
    Input the list: 12 4 5 2 7 19 26 8
    
    12  ************
    4   ****
    5   *****
    2   **
    7   *******
    19  *******************
    26  **************************
    8   ********
    

  5. Use the 'script' command to record your program running. Name your script file lab5.script.

  6. Turn in the '.cxx' file for your program as well as your script file, using the turnin program. Use the following command line:

       /cs/bin/turnin submit cs1005 lab5 lab5.cxx lab5.script
    


Glynis Hamel 2003-01-17



Glynis Hamel 2003-01-17