Classwork 11: Functions & Libraries

Thursday, August 3, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Create three files named cw11.c shapes.h shapes.c
  2. To compile with multiple files you will want to compile as follows:
    	gcc -Wall cw11.c shapes.c -o cw11
    
    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.
  3. Create a shapes library by accomplishing the following:
    1. Start off by guarding shapes.h using the #ifndef... statements that we discussed in class. Make sure you include all three statements.
    2. 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.
    3. In your shapes.c file remember to use #include "shapes.h" so that the function prototypes are include in this file.
    4. Write the code necessary for having Draw_Circle, Draw_Square, and Draw_Rectangle produce shapes using the '*' character.
  4. Create a main() in your cw11.c file that will accomplish the following:
    1. Present a greeting to the user on what the program will accomplish.
    2. 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'

    3. 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'.
    4. Depending on the function called, you will need to read in the required dimensions for the shape that is to be drawn.
    5. The program will continue to run until the user enters the quit command.
  5. You must create functions for printing the menu and greetings. They must be written in cw11.c.
  6. Create a typescript file containing your code running that shows all shapes being drawn in a single execution of cw11.
  7. linux3[26]% submit cs104 cw11 cw11.c shapes.c shapes.h typescript
    

  8. After submitting your files, you can verify your files were submitted by using the submitls command
  9. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!