Program 1 - Barometers are Falling
This is your first programming assignment. If you finish it on or before this date, I will go ahead and grade it.
Normally these assignments will be homework assignments, but this time out, I thought it best to devote a lab period to this as this is the very first time you will be writing programs on your own. Just relax, and do your best. Don't be afraid to make mistakes. Don't be afraid of testing incomplete programs!
Remember, a true coder feels the source flowing through them.
A physics professor asked one of his students, "How could we determine the height of a building using a barometer?" The student replied, "I could tie a string to the barometer and lower it to the ground from the top. Then I could measure the string." The physics professor chuckled and said, "I want a more physics based solution." The student then said "Ok, I could drop the barometer from the top of the building and then time its descent and then calculate the height using the formula . That's brilliant!" Much to the professor's horror, before he could correct his student the boy snatched the professor's prized barometer and raced to the stairs.
Now, we know the professor is going to lose his barometer, so the least we can do is to help him make the most of it. We are going to design and implement a program which will measure the height of the building in terms of barometric catastrophe. A sample run of this program might be:
Drop your barometer. How long was it until you heard a crashing sound (in seconds)? 2.5 Your building is 30.6563 meters tall. Now, you do realize that barometers are filled with mercury, right? Call the EPA NOW!
Your job is to write the program that does the above calculations. You should ask for a value in seconds, and display the result in meters. Your program output can be customized a bit if you like, but it will be graded by script. The script is looking for the correct number, followed by " meters tall". For instance, had the program above simply stated:
30.65 meters tall
It would have been fine.
Really, you should just work from the problem statement. But, since this is your first time out, I will give you a procedure to follow to create a good program.
- Your first task is to think the problem through. Work out a few heights by hand. Identify variables and constants.
- Now, turn your attention to some development notes. Write out, in English, what your program should do. Maybe even draw some doodles beside it. Do whatever it takes to get your mind focused on this problem.
- Open your terminal, change into Program-1 directory.
- Using your favorite text editor, create a file called "barometer.cpp" and add all our basic stuff into it. In addition to the basics, include your name in a comment at the top of the file. (This is the equivalent to putting your name on a paper for submission.)
- Use your notes to write your comments in the main function. Write the comments before writing any code.
- Create your variables, and document what they are with comments.
- Write the code that makes it all happen.
- Run your hand computed test cases through your program to verify that it works.
- Once your program works, you're done!
Grading Procedure and Criteria
Create a folder called 'programs/program1' in your cs1 folder. This is the folder where you will do your work. When you turn it in, I will take it up from within the system. Be sure to add, commit, and push! Let me know if you finish it early, and I will go ahead and grade it.
The grading criteria for this lab are:
|Proper use of Blank Lines||5|
|Comments are adequate||15|
|Functionality (it works)||70|
- We want to make the program give output in meters. Therefore, our gravitational acceleration constant is .
- C++ does not have an exponent operator, therefore should be written as t*t.
- Yoda may have been on to something after all!