CMSC104, Summer 2002

Programming Project 2

Rectangles

Out: Tuesday, June 25, 2002
Due: Tuesday, July 2, 2002 before midnight


The Objective

This project is designed to give you practice with nested for loops and switch statements, as well as experience working with functions from the math library.

The Task

The program you write will deal with rectangles. You will plot a filled-in rectangle using an ascii character, where the width of the rectangle will be plotted by letting each ascii character express one/half a unit across in a row (so 2 characters per unit across) and where the height of the rectangle will be plotted by letting the height of each ascii character be one unit.

########## Here's an example of a rectangle that ########## has a width of 5 and a height of 4 and ########## is plotted using the '#' 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.

You will ask the user to input the width of the rectangle, the height of the rectangle and also the ascii character you should use to display the rectangle. For example, if the user entered a width of 5, a height of 2 and the character '*', the menu option print would display:

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

You SHOULD NOT allow the user to enter negative numbers as the dimensions of the rectangle. You should error check the input and allow the user to keep entering numbers until he/she enters a positive number. See the sample output below.

After getting the user input, you must present a menu to the user. The menu should have six options. Each option will perform a different task.


Sample Output

Enter the width: -4 Please enter a positive integer: -2 Please enter a positive integer: 4 Enter the height: 3 Enter a character to be used to draw the rectangle: # Menu A -- Calculate the Area of the Rectangle P -- Calculate the Perimeter of the Rectangle D -- Calculate the Length of the Diagonal of the Rectangle R -- Display the Solid Rectangle H -- Display the Hollow Rectangle Q -- Quit Selection: D The length of the diagonal is: 5.000 Menu A -- Calculate the Area of the Rectangle P -- Calculate the Perimeter of the Rectangle D -- Calculate the Length of the Diagonal of the Rectangle R -- Display the Rectangle R -- Display the Solid Rectangle H -- Display the Hollow Rectangle Q -- Quit Selection: T T is an invalid menu option. Menu A -- Calculate the Area of the Rectangle P -- Calculate the Perimeter of the Rectangle D -- Calculate the Length of the Diagonal of the Rectangle R -- Display the Solid Rectangle H -- Display the Hollow Rectangle Q -- Quit Selection: r r is in invalid menu option. Menu A -- Calculate the Area of the Rectangle P -- Calculate the Perimeter of the Rectangle D -- Calculate the Length of the Diagonal of the Rectangle R -- Display the Solid Rectangle H -- Display the Hollow Rectangle Q -- Quit Selection: R A solid rectangle with 4 columns and 3 rows ######## ######## ######## Menu A -- Calculate the Area of the Rectangle P -- Calculate the Perimeter of the Rectangle D -- Calculate the Length of the Diagonal of the Rectangle R -- Display the Solid Rectangle H -- Display the Hollow Rectangle Q -- Quit Selection: H A hollow rectangle with 4 columns and 3 rows ######## ## ## ######## Menu A -- Calculate the Area of the Rectangle P -- Calculate the Perimeter of the Rectangle D -- Calculate the Length of the Diagonal of the Rectangle R -- Display the Solid Rectangle H -- Display the Hollow Rectangle Q -- Quit Selection: Q Have a nice day!


Submitting the Program

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

submit cs104 Proj2 proj2.c

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command.

submitls cs104 Proj2