Assignment 4 - CS 1711 - Fall 1999

Due: Wednesday, November 24, 4:30 pm

Question 1

Write a menu program using the switch/case construction. The menu should display 4 choices in the form:
1.    first name
2.    last name
3.    telephone number
4.    year of birth
Input one of 1, 2, 3, 4 >

If the user enters one of the choices 1, 2, 3, or 4, the program displays an appropriate prompt. For example, if the user enters menu choice 4 then a prompt is displayed:    Input year of birth >
and the data entered is accepted. If the user enters something other than one of the choices 1...4, the program displays an error message
        Incorrect menu choice...Enter one of 1, 2, 3, or 4.
        Press <Enter> to return to the menu >
, waits until the user presses the <Enter> key, and then redisplays the menu. The user can enter the data for the 4 choices in any order, The prompt at the bottom of the menu should change depending on the items previously selected, so for example, if the user has already entered the data for menu choices  3, 4, then the prompt at the bottom of the menu would be
        Input one of 1, 2 >
Once the user has chosen each of 1, 2, 3, 4 and has entered the data requested at the prompts, the program displays the data in the form:
        Name:    Jane Doe
    Phone:   364-1234
    Birth:   1978
File name:   Save the program as menu.cpp

Question 2

Write a program which contains a (free) function long factorial (int n) which returns the factorial ( !) of an integer n.
Note that n! = n.(n-1)(n-2)...(3)(2)(1). Use a (counted) for loop to create the function. The driver program should repeatedly prompt the user for entry of an integer value, and should display the factorial of the integer entered. The program should terminate when the user enters 0.
Sample run
Program to calculate factorials.
Enter a positive integer (enter 0 to stop)
Integer > 3
3! = 6
Integer > 5
5! = 120
Integer > 0
Press any key to continue

File name: Save the program as factoria.cpp - NOTE CHANGE!