Hands On C++: Project 6


The Projects

Your instructor will assign you one of the problems below. To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Following the pattern in the lab exercise, first, design using OCD; then code your design in C++ using stepwise translation; finally, test your program thoroughly.

Project #6.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.

Project #6.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 even 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.

Project #6.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 was a leap year because it is divisible by 400, but 2100 will not be a leap year because it is divisible by 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.

Project #6.4: Using the metric library you created for the project of Lab #4, write a menu-driven program that permits the user to select one of the metric conversions in the library.

Turn In

Turn the following things:

  1. This grade sheet.
  2. Your OCD.
  3. Your source program.
  4. The output from an execution of your program.


Lab Home Page | Lab Exercise
© 2003 by Prentice Hall. All rights reserved.
Report all errors to Jeremy D. Frens.