Classwork 5: Functions
Tuesday, July 17, 2012[Previous Classwork] [Next Classwork]
Complete the following:
- Ensure the machine is booted into Linux
- Login to Linux
- Open a termimal from the top left Applications menu -> System Tools -> Terminal
- Create a directory called cw05 to store this classwork
- Go into your new cw05 directory
- Create a new file using the editor you like (nano, vi, emacs, xemacs) called cw05.c
- Type a comment for the header based on the template below:
/* File: cw05.c Name: A. Student Username: astudent1 Date: 10/24/07 Description: ... */
- Add the #includes to allow us to use scanf and printf
- Create a function called "read_value" that when called will:
- print out a string asking for the user to input one integer
- use scanf to read the value
- then return that value to the caller
- Create a function called "average" that when called will:
- add together 4 integer values
- return the average of the 4 values as a double.
- Create a main() that will:
- call read_value 4 times to get user input
- call average with the 4 values returned from each call to read_value
- print out the result returned from the call to average
- Note that the user input must occur in "read_value" and the printout must occur in "main" for full credit
- Once you are sure the program is done and working well, start a script using script
- Once the script is running, show you compiling your program, and then running the program three times, typing in different values each time.
- Exit from the script, which will save the log typescript
- Once you are done, use submit to submit two files, cw05.c and typescript
linux3[26]% submit cs104 cw05 cw05.c typescript
- After submitting your files, you can verify your files were submitted by using the submitls command as shown below
linux3[26]% submitls cs104 cw05
- MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!