Classwork 11: Functions & Libraries
Thursday, August 3, 2012[Previous Classwork] [Next Classwork]
Complete the following:
- Create three files named cw11.c shapes.h shapes.c
- To compile with multiple files you will want to compile as follows:
Please note that only source files are compiled. The -o flag will rename the executable from a.out to cw11. You have been doing this all semester.
gcc -Wall cw11.c shapes.c -o cw11
- Create a shapes library by accomplishing the following:
- Start off by guarding shapes.h using the #ifndef... statements that we discussed in class. Make sure you include all three statements.
- In your shapes.h file create three function prototypes names:
- Draw_Circle - this function needs to take one integer for the radius of the circle.
- Draw_Square - this function needs to take one integer for the length of the four sides of the square.
- Draw_Rectangle - this function needs to take two integers for the length and width of the sides of the rectangle.
- In your shapes.c file remember to use #include "shapes.h" so that the function prototypes are include in this file.
- Write the code necessary for having Draw_Circle, Draw_Square, and Draw_Rectangle produce shapes using the '*' character.
- Create a main() in your cw11.c file that will accomplish the following:
- Present a greeting to the user on what the program will accomplish.
- Present a menu to the user of the options to draw any of the shapes contained in the shapes library.
'S - Draw Square'
'R - Draw Rectangle'
'C - Draw Circle'
'Q - Quit' - Read the user's menu choice and call the correct function. You must account for upper and lower case characters. For example: 'R - Draw Rectangle' a user should be able to enter 'R' or 'r'.
- Depending on the function called, you will need to read in the required dimensions for the shape that is to be drawn.
- The program will continue to run until the user enters the quit command.
- You must create functions for printing the menu and greetings. They must be written in cw11.c.
- Create a typescript file containing your code running that shows all shapes being drawn in a single execution of cw11.
-
linux3[26]% submit cs104 cw11 cw11.c shapes.c shapes.h typescript
- After submitting your files, you can verify your files were submitted by using the submitls command
- MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!