Classwork 5: Functions

Tuesday, July 17, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Ensure the machine is booted into Linux
  2. Login to Linux
  3. Open a termimal from the top left Applications menu -> System Tools -> Terminal
  4. Create a directory called cw05 to store this classwork
  5. Go into your new cw05 directory
  6. Create a new file using the editor you like (nano, vi, emacs, xemacs) called cw05.c
  7. Type a comment for the header based on the template below:

    /*   File: cw05.c
         Name: A. Student
         Username: astudent1
         Date: 10/24/07
         Description: ...
    */
    

  8. Add the #includes to allow us to use scanf and printf
  9. Create a function called "read_value" that when called will:
    1. print out a string asking for the user to input one integer
    2. use scanf to read the value
    3. then return that value to the caller
  10. Create a function called "average" that when called will:
    1. add together 4 integer values
    2. return the average of the 4 values as a double.
  11. Create a main() that will:
    1. call read_value 4 times to get user input
    2. call average with the 4 values returned from each call to read_value
    3. print out the result returned from the call to average
  12. Note that the user input must occur in "read_value" and the printout must occur in "main" for full credit
  13. Once you are sure the program is done and working well, start a script using script
  14. Once the script is running, show you compiling your program, and then running the program three times, typing in different values each time.
  15. Exit from the script, which will save the log typescript
  16. Once you are done, use submit to submit two files, cw05.c and typescript

    linux3[26]% submit cs104 cw05 cw05.c typescript
    

  17. After submitting your files, you can verify your files were submitted by using the submitls command as shown below

    linux3[26]% submitls cs104 cw05
    

  18. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!