Home | |
Schedule | |
Assignments | |
Lectures | |
Resources
Project One Specifications
Introduction: Though the semester is not very old, you know about variables and constants, their types and about C++ statements that assign them values. You know how to write arithmetic expressions. You know the fundamentals of input through the keyboard and output to the monitor screen and to files. You also know how programs are formatted. This project will give you a chance to work with all these things. Program description: Imagine you are a skydiver and you are planning your next parachute jump. You know that to land safely, you must pull the ripcord a certain number of feet above the ground, as long as your velocity is not too high. You would like to write a program to help you decide how long it is safe to wait before pulling the ripcord. In other words, the program will use information about your initial height (yi) and velocity (vi) and use it to calculate what your final height and velocity will be after some number of seconds (t). The formulas you will need are: final_position = yi - (vi * t) - (0.5 * g * t2) final_velocity = vi + g * t Here, yi is the initial position (in feet), vi is the initial velocity (in feet/sec), t is the elapsed time (in seconds) and g is the gravitational acceleration (32.0 ft/sec/sec). Your program will prompt a user to enter an initial position, an initial velocity and a time in that order. The input will be provided from keyboard. The program will compute the final position and velocity. Finally your program will write to a file (in a very tightly specified format) the three items of data (initial position, initial velocity and time) and the two computed numbers (final position and final velocity).
Project specifications:
2. At the top of the file, write preprocessor directives to provide for standard and file related C++ input and output and for the detailed manipulation of output. 3. Place all of your code in a single function, int main(void). 4. At the beginning of main(), declare GRAVITY, the gravitational acceleration, as a constant with value 32.0. 5. Declare variables to hold user-supplied values for the initial position, the initial velocity and the time. Make sure to use descriptive variable names (i.e. Don't use vi for the initial velocity, use initial_velocity or some other descriptive name). 6. Prompt the user to enter his/her initial position. Read the value into the variable that you have declared for that purpose, and immediately write that value back to the screen. (The immediate writing of users' inputs back to the screen is called 'echo printing.' Echo printing helps you verify that there have been no problems in obtaining input, that the correct input has been stored, and it helps us grade your projects. You will echo print for every input obtained from the keyboard in every project written for this course unless specified otherwise. You will get used to it). Prompt for, read and echo print a value for the initial velocity. Prompt for, read and echo print a value for the time. 7. At some point in writing this project you will need to compute the values of final position and velocity. The formulas that you will need at that point are the ones which appear previously in this specification. 8. Open a file named myproj1.out for output, and write code to assure that the text that appears in the file looks exactly like that displayed in the section below called Specifications for Output. 9. Close any files that need to be closed and return control to the operating system.
Specifications for Output:
Enter the initial position ==> 5678.2 5678.2 Enter the initial velocity ==> 43.3 43.3 Enter the time ==> 9.03 9.03
The output from a single run of your program must match the following
as closely as possible.
In particular, a line of minus signs must mark the start and the end of output. Equal signs
must be aligned as shown. Decimal points must be aligned as shown. Two digits must be
shown to the right of the decimal points in every number displayed. White space (blank lines)
must be used judiciously and effectively. Please place a couple of blank lines before the first
line of minus signs and a couple more after the last line of minus signs. The output in
myproj1.out will look like the following:
--------------------------------------------------- The initial position = 5678.20 feet. The initial velocity = 43.30 feet/sec. The elapsed time = 9.03 seconds. The final position = 3982.55 feet. The final velocity = 332.26 feet/sec. --------------------------------------------------- Specifications for Documentation and Format:
Program testing:
Then run your project by typing: ./proj1 Enter some sample initial positions, initial velocities and times. Make sure the program produces an output file named myproj1.out. You can view the contents of the output file by typing:
in the terminal window, or by opening the file in an emacs editor. Make sure the format of the output is as specified above. Automatic Testing
To submit your Finished Project:
2. Print out the grading header , put your name at the top and staple it to the front of a hard copy of the files you submitted electronically. 3. Hand in a hard copy of the program file and the collaboration log you submitted electronically along with the header. Hand this in to your instructor at the beginning of class on the project's due date. Note: The submit program might compile your program before accepting it. (Depending on how your instructor sets the defaults.) If your program does not compile successfully or if something else is wrong with your submission, the submit program will report to you that the submission failed and it will give you a (sometimes cryptic) reason for the failure. You may submit version after version of proj1.cc. Each successful submission will replace any previously successfully submitted version. That is, only your last successfully submitted version will be visible to and will be graded by your instructor or her/his grader. Get started early and have fun! Honor code: Please review the collaboration policy on the main course webpage. Also refer to the math and CS department honor code policy. Home | | Schedule | | Assignments | | Lectures | | Resources
Constance Royden--croyden@cs.holycross.edu
|