Hands On C++: Project 7


Objectives

1. Practice using value and reference parameters.
2. Practice building more sophisticated functions.

Introduction

In each of the following projects, you are to build a function that uses reference parameters. Your instructor will tell you which one of the projects to do.

Projects

7.1. White water rapids are classified by their gradient (the number of feet per mile they descend) and their class (a difficulty rating in the range 1-6, with 1 being calm and 6 being unnavigable.) Popular white water rafting trips in Pennsylvania and West Virginia include the lower Youghiogheny (gradient 15, class 3), the New (gradient 25, class 4), the Cheat (gradient 35, class 4), and the Upper Youghiogheny (gradient 125, class 5).

Write a menu-drive program that displays a menu of the trips, and displays the gradient and class of whatever trip the user selects. Your program should include a function that, given the trip selected by the user, passes back the gradient and class of that trip.

7.2. Write a function Sort3() that, given three integer arguments int1, int2 and int3, changes the values of those arguments so that their values are in ascending order (i.e., int1 <= int2 <= int3). Write a driver program that demonstrates the correctness of Sort3().

7.3. Your local painting supplies store would like a paint-mixing "expert system." Write a function that, given a non-primary color (i.e., orange, green, purple) will pass back the two primary colors that must be mixed to produce that color (i.e., red and yellow must be mixed to produce orange, yellow and blue to produce green, and blue and red to produce purple). Use a string object to store a color. Then write a menu-driven program that allows its user to enter, process and display the solution of as many paint-mixing problems as s/he wishes.

7.4. A quadratic equation is an equation of the form

   ax2 + bx + c = 0
Write a function that, given the a, b and c values defining a quadratic, passes back the two roots of that quadratic. To compute the roots, use the quadratic formula:
  roots = -b ± sqrt(b2 - 4ac)
          --------------------
                 2a
Your function should check for common errors, such as a == 0 and b2 - 4ac being negative.

Create a user-friendly driver program that allows its user to compute the roots of an arbitrary number of quadratic equations.

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 (using script).

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.