Classwork 16: Function Prototypes


To practice writing the function prototype for a simple function and practice implementing a simple function.


Your assignment is to implement a simple function that determines whether a box is larger than a shoebox. The function that you implement must be compatible with the main program in this file: main16.c.

/* File: main16.c Name: CMSC104 Section 4 Classwork 16 Tuesday 10/25/2011 */ #include <stdio.h> /* Insert the function prototype for isBiggerThanShoeBox() here */ /* Do not change the main progam */ int main() { float h, l, w ; printf("Enter the dimension of your shoebox.\n") ; printf("Enter height: ") ; scanf("%f", &h) ; printf("Enter length: ") ; scanf("%f", &l) ; printf("Enter width: ") ; scanf("%f", &w) ; if (isBiggerThanShoeBox(h, l, w) ) { printf("Yes, your box is larger than a shoebox\n") ; } else { printf("No, your box is smaller than a shoebox\n") ; } return 0 ; } /* end of main program */ /* Insert your implementation of isBiggerThanShoeBox() below */

The function takes three floating point parameters which correspond to the height, length and width of a box. We will define a "standard" shoebox to be 4 inches high, 11.75 inches long and 7.25 inches wide. If a box is taller, longer or wider than the standard shoebox, then your function should return 1 to indicate true. Otherwise, the box in question is considered smaller than a shoebox and your function should return 0.

Step 1:

First, download the main program in the file main16.c. Make sure you save it with a filename that ends with .c.

Using the information given above, including the source code of the main program, write the function prototype for the function isBiggerThanShoeBox() and insert it above the main function as indicated.

Step 2:

Below the main program, write the C code to implement the isBiggerThanShoeBox() function. Your function must be compatible with the main() function as given. You must not alter the code in main() in any way.

Compile and run your program. Use the -Wall option with gcc. Your program should compile without any warnings or errors.


Use the script command to record yourself compiling and running the program. Submit your C source code and the typescript file as usual:

submit cs104_chang cw16 main16.c
submit cs104_chang cw16 typescript

Be sure to logout completely when you have finished!