Topical Information

This program gives you practice with branching and looping.

Program Information

Code a menu that allows the user to choose between finding the midpoint of or the distance between two points. The final option should be to quit.

Allow them to enter menu options by either the number or a capitalized letter (make each option's special letter unique!).


As an example, you might have the program interaction look something like (the parts in this color are typed by the user):

$ ./pt_menu.out

                 Welcome to the Point Menu Program!!!

    1) calculate Distance between two points
    2) calculate Midpoint of two points
    3) Quit

    Choice:  n

I'm sorry, that choice is invalid!

Please try to read/type more carefully next time...

    1) calculate Distance between two points
    2) calculate Midpoint of two points
    3) Quit

    Choice:  mid


Where is your first point?  (3.4, 12.2)
Where is your second point?  (13.4, 12.2)

The midpoint of the line segment from (3.4, 12.2) to
(13.4, 12.2) is (8.4, 12.2).


    1) calculate Distance between two points
    2) calculate Midpoint of two points
    3) Quit

    Choice:  D


Where is your first point?  (3.4, 12.2)
Where is your second point?  (13.4, 12.2)

(3.4, 12.2) is 10 units away from (13.4, 12.2).


    1) calculate Distance between two points
    2) calculate Midpoint of two points
    3) Quit

    Choice:  3

Thank you for using the PMP!!

Endeavor to have a transcendental day!

$

Be careful that they don't derail your program with words for menu choices!

Thought Provoking Questions

  1. How do you get the menu to repeat until they choose the quit option?

  2. How do you detect when they've entered something invalid?

  3. Can you easily check for both upper- and lower- case menu entries? (What library function might help here?)

  4. How can you dispose of the excess of a word they may have typed at the choice prompt? (Hint: It's a special case of optional trailing data that we've been using for what seems like forever...)

  5. How many tests would be needed to thoroughly (i.e. the menu, the calculations, ...everything) test this application?

This assignment is (Level 2).

Options