Improved Barometer Drop

From Maryville College CS Wiki
Jump to: navigation, search

Problem Statement

The professor, angry at the loss of his favorite barometer, was less than patient when his wayward pupil returned. "You chowder head! That barometer has been in my family for over 4 generations!", he said. The boy replied "Sorry, but I was so excited, I also wrote this program to go with it." Never missing a chance to read good C++ code (I mean, who would?) he read over the work of his student.

"Hmmm, this code is good. Not bad for a first attempt." the professor said. "What do you mean not bad?", the student replied. "Well, I would prefer if it could solve more aspects of the problem at hand. For instance, we live in the US, and thanks to the failings of the Carter administration, we still use the imperial system. It would be nice if it could work in both imperial and SI units. Also, it would be great if it could predict the number of seconds of a fall from a given height, as well as the final velocity of the fall."

The student thought it over for a second and said "Well, it would be easy enough to store some choice variable about units. But what about the other parts?" The professor went to the board and wrote out several formulas in almost legible handwriting. He, of course, quickly erased them, but our intrepid student captured them! After all, he knows that you have to be quick on the draw to capture professorial notes!


d = \displaystyle\frac{1}{2} gt^2


t = \sqrt{\displaystyle\frac{2d}{g}}



v=gt

Also, he noted something about g being different in imperial units than it is in SI units. Unfortunately, the professor was too quick with the eraser for him to capture that one. Oh well, that's why google was invented!


Procedure

We are going to modify your barometer program from program 1. Start by copying barometer.cpp to the Program-2 folder.

1. Modify the design of the program from last time to account for the change in requirements. Below are a few sample runs to illustrate how the changed program should behave:

 > ./barometer
 Will you be working in:
    1.) Metric
    2.) Imperial
 Choice? 1
 
 What mode will you want?
    1.) Height in terms of time.
    2.) Time in terms of height.
 Choice? 1
 
 Drop your barometer.
 How long was it until you heard a crashing sound (in seconds)? 2.5
 
 Your building is 30.6563 meters tall.
 The final velocity of the barometer was 24.525 m/s
 Now, you do realize that barometers are filled with mercury,
 right?  Call the EPA NOW!

Another run:

 ./barometer
 Will you be working in:
    1.) Metric
    2.) Imperial
 Choice? 1
 
 What mode will you want?
    1.) Height in terms of time.
    2.) Time in terms of height.
 Choice? 2
 
 How tall is your building? 30
 The barometer will hit the ground in 2.4731 seconds.
 The final velocity of the barometer was 24.2611 m/s
 Now, you do realize that barometers are filled with mercury,
 right?  Call the EPA NOW!

And a couple more times!

 > ./barometer
 Will you be working in:
    1.) Metric
    2.) Imperial
 Choice? 2
 
 What mode will you want?
    1.) Height in terms of time.
    2.) Time in terms of height.
 Choice? 1
 
 Drop your barometer.
 How long was it until you heard a crashing sound (in seconds)? 2.5
 
 Your building is 100.531 feet tall.
 The final velocity of the barometer was 80.425ft/s
 Now, you do realize that barometers are filled with mercury,
 right?  Call the EPA NOW!
 
 
 > ./barometer
 Will you be working in:
    1.) Metric
    2.) Imperial
 Choice? 2
   
 What mode will you want?
    1.) Height in terms of time.
    2.) Time in terms of height.
 Choice? 2
   
 How tall is your building? 100.5
 The barometer will hit the ground in 2.49961 seconds.
 The final velocity of the barometer was 80.4125ft/s
 Now, you do realize that barometers are filled with mercury,
 right?  Call the EPA NOW!

Note that the final velocity is always printed, and it should display the proper units. For metric, use m/s and for imperial, use ft/s. Take note of how the units are expressed in the above example. You'll need to match it to get full credit!

2. Modify your code to allow for these changes.

3. Once your program is done, leave barometer.cpp in your Program-2 directory for grading!

Grading Criteria

Category Points
Proper Indentation 5
Proper use of Blank Lines 5
Comments are adequate 15
Variable names 5
Functionality (it works) 70