CMSC 104
Sections 103/105/401
Programming Project Three

The 2-Number Menu

Assigned: Wednesday 4/21/99
Due: Before Midnight Tuesday 5/4//99

The Objective

The purpose of this project is to give you practice writing C programs with while loops, switches and functions.

The Background

In systems which do not support a Graphical User Interface (GUI), it is necessary to present the user with a list of commands in the form of a menu. The user chooses a selection from the menu and the program performs the associated task.

The Task

Your task is to write a program that implements a menu of commands which operate on two integers. Your menu must support the following commands:

  1. Enter two new integers, N1 and N2
  2. Determine which integer is the larger
  3. Compute the average of N1 and N2 and print with 2 decimal places
  4. Determine if N1 is a multiple of N2 or if N2 is a multiple of N1
  5. Compute N1 to the N2 power
  6. Determine if N1 is a multiple of N2
  7. Draw a rectangle of *s with N1 rows and N2 columns
  8. Quit

The user should input a letter which corresponds to his menu choice. Use the getchar() function to input the menu selection (watch out for those newlines!). Your program should accept both uppercase and lowercase letters for the commands. Use the following letters:

Your program may assume the following that the user will input integers (not floating point) where required (but watch out for negatives and zero), and will input a single character and ENTER when choosing from the menu.

Required Functions

Your program must include functions with the following prototypes

Other program requirements

Be sure that your program is "robust", meaning

Be sure that your program has a file header comment that includes
  1. the name of the file
  2. your name
  3. the date the file was written
  4. a description of your program
  5. your algorithm or pseudo-code to solve the problem
and all functions have appropriate function header comments as discussed in class.

Your program must adhere to the coding standards and indentation styles discussed in class.
Be sure your project is well commented.
See course syllabus for project grading guidelines and university policies concerning sharing of code.

Sample Output

retriever[102] a.out Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: t Invalid Menu Selection: t Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: L Please execute command 'I' first Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: i Please enter a postive integer: -4 -4 is not Postive, please try again Please enter a postive integer: 5 N1 = 5 Please enter a postive integer: 6 N2 = 6 Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: L 6 is larger than 5 Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: a The average of 5 and 6 is 5.50 Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: p 5 to the 6 power is 15625.00 Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: r A rectangle with 5 rows and 6 columns ****** ****** ****** ****** ****** Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: R A rectangle with 5 rows and 6 columns ****** ****** ****** ****** ****** Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: M 5 is NOT a multiple of 6 Menu List I -- Enter Integers L -- Determine Larger Integer A -- Calculate the average of N1 and N2 P -- Raise N1 to the N2 power M -- Is N1 a multiple of N2? R -- Draw a rectangle with N1 rows and N2 columns Q -- Quit Selection: q bye for now retriever[103]

Although your output need not be identical to the above, all information must be present.

Compiling your code

Since this project requires the use of the C math library (because we are using the pow() function), the command for compiling your program is slightly different than before. Use the command:

cc proj3.c -lm

The -lm at the end tells the linker that we wish to use the math library

Submitting the Program

Your C source code file for this project MUST be called proj3.c.
To submit your project, type the following at the Unix prompt:

submit cs104-103 proj3 proj3.c

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

submitls cs104-103 proj3