UMBC CMSC 104 Spring 2001 CSEE | 104 | current 104

CMSC 104, Spring 2001

Project 7 - Rectangles

Due Date: Midnight, Tuesday May 8

Note: No late projects will be accepted.

Point Value:

This project is worth 75 points.

Objectives:

Assignment:

Your program will display a filled-in rectangle of a given ASCII character. The width of the rectangle will be displayed by letting each ASCII character represent one/half of a unit across in a row (so 2 characters per unit across). The height of the rectangle will be displayed by letting the height of each ASCII character be one unit.

########## Here is an example of a rectangle that ########## has a width of 5 and a height of 4 and ########## is drawn using the ASCII character '#'. ##########

Using two characters across for a unit and one character per unit down will give you a rectangle that more closely resembles the dimensions you'd like to see. This is because printed ASCII characters are approximately twice as tall as they are wide.

The program will ask the user to enter the width of the rectangle, the height of the rectangle, and the ASCII character to be used to display the rectangle. For example, if the user enters a width of 5, a height of 2, and the character '*', the function DrawRect() will display:

********** **********

You may assume that the user will only enter integer values greater than zero for the height and width.

After getting the user input, you must present a menu to the user. The menu should have the five options shown in the Sample Output below. The functions you will write, in addition to the main function, are:

Each function corresponds to a menu option. The menu should continue to display until the user enters a 5 to quit. If the user enters a number not in the range of 1 to 5, inclusive, you should display the message "Menu choice must be in the range of 1 to 5" and redisplay the menu.

Notes:


Sample Output

Enter the width: 7 Enter the height: 5 Enter a character to be used to draw the rectangle: & Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 0 Menu choice must be in the range of 1 to 5 Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 6 Menu choice must be in the range of 1 to 5 Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 1 The area is: 35 Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 2 The perimeter is: 24 Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 3 The length of the diagonal is: 8.602 Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 4 A rectangle with 7 columns and 5 rows &&&&&&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&&& Menu 1) Calculate the Area of the Rectangle 2) Calculate the Perimeter of the Rectangle 3) Calculate the Length of the Diagonal of the Rectangle 4) Display the Rectangle 5) Quit Enter your choice (1 to 5): 5 End of program.


Important Note : You must tell the compiler where to find the math library, or your program will not compile. This is accomplished by using the -lm (the lowercase letter 'l', not the number one) option when compiling. So, in order to compile a program that calls a function in the math library, not only do you have to #include the math.h header file, but you also must compile with the -lm option. So, compile your program as follows:

gcc -ansi -Wall -lm proj7.c

Coding Standards:

Note that you MUST adhere to the coding standards and indentation style given on the Projects home page. Don't forget your function header comments!

Project Submission:

Submit your project by e-mailing your source code (proj7.c) to Evelyn (cwang3@cs.umbc.edu) as an attachment. Make the Subject of the e-mail Project 7 so that Evelyn knows what it is. Do NOT send your executable file (a.out).