Hands On C++: Project 5


Objectives

1. Practice using selective behavior.
2. Practice constructing conditions.
3. Practice program maintenance.

Introduction

Your instructor will tell you which one of the following projects to do.

Projects

5.1. There are three possible sources of user error in calculate.cpp:

  1. The user could enter an invalid operation (something other than +, -, * or /).
  2. The user could enter a non-numeric value for op1 or op2.
  3. The user could enter / for operation and 0 for op2 (i.e., a divide-by-zero error).
Our program uses assert() to guard against these errors, but the diagnostic message displayed by assert() is not particularly informative or user-friendly. Replace each of the calls to assert() in calculate.cpp with a selective-behavior statement that displays a more user-friendly diagnostic message and terminates the program (using exit() from cstdlib) if the user enters erroneous information.

5.2. Write a menu-driven "police sketch artist" program. The program should use four different menus for:

Each menu must provide at least four different choices. Your program should display "sketches" of the person being described, along the lines of those below (hopefully yours will be better!):
      -----
     |     |        .......     \|||||||/
    ---------       .     .      |     |
    (| O O |)      (|-0-0-|)    (| . . |)
     |  _\ |        |  ^  |      |  >  |
     |\___/|        | --- |      |||-|||
      -----          -----        |||||
                                   ||| 
Organize your program in such a way that it contains no redundant code. For each of the user's choices, write a separate function to process that choice.

5.3. A year is a leap year if it is evenly divisible by 4, unless it is divisible by 100, in which case it must also be divisible by 400. That is, 1996 was a leap year because it is divisible by 4 and not 100, 1997 was not a leap year because it is not divisible by 4, 2000 will be a leap year because it is divisible by 4 and 400, but 2100 will not be a leap year because it is divisible by 4 and 100 but not 400.

Write a LeapYear() function that, given a year, returns true if that year is a leap year, and returns false otherwise. Then write a driver program that tests your function.

5.4. Using the metric library you created in lab 3a, write a menu-driven program that permits the user to select and perform any one of the metric conversions in the library.

Turn In: A hard copy of this grade sheet, attached to hard copies of

  1. all source files you created for this project; and
  2. the output from an execution of your executable program.

Don't forget to clean up your directory when you are all finished...


Back to the Lab Exercise

Back to This Lab's Home Page


Copyright 1998 by Joel C. Adams. All rights reserved.