CSCI 131 - Techniques in Programming, Spring 2014

    Home | | Schedule | | Assignments | | Lectures | | Resources

    Project One Specifications
    Jumping from Planes

    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:
    1. Place all your code in a file named proj1.cc. (Note, for grading your project will be run automatically by the computer, so the filename must be exact).

    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:
    Directly below, you can see the display that will appear on the monitor screen during the data prompting, data gathering, and data echoing phase of the program. Note that the first time a number appears, it is the user input. The second time you see the same number, it is the echo printing.

    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:
    Normally, you will be expected to determine what documentation and formatting will be necessary for your project on our own, with the help of the Style Guide in your Lab manual. but this is, after all, your first project requiring documentation. Fully correct documentation for Project 1 must include:

    • A file prologue at the top of your program file. The prologue must contain the project number, title, your name, the date, and your instructor's name. The prologue must also contain a full description of the project.
    • A comment describing the role of each variable and each constant declared anywhere in the project.
    • A comment, //end of , anywhere a block-ending bracket, '}', appears. In Project 1, the only '}' appears at the end of main(). So the documentation will look like
                  .... //end of main()
      

    Program testing:
    First, you should test your program with your own test data. Compile your program using the compile command:

      g++ -g -Wall proj1.cc -o proj1

    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:

      more myproj1.out

    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
    Once you think your program works correctly, you can test it with an automatic testing program. The directory ~csci131/PROJECTS/PROJ1 contains, among other things, files named test1, proj1a.dat, proj1b.dat, and proj1c.dat. Copy these files into a directory which also contains your proj1.cc. Then type ./test1. The program test1 (called a script) will compile your program and run it three times, once using proj1a.dat for input, once using proj1b.dat for input and a final time using proj1c.dat for input. Each time your program runs, it will write its output to your file named myproj1.out and test1 will append this output to a file named output. This file will appear in the same directory into which you copied test1. The perfect output, well, the output created by my own proj1.cc, can be seen in ~csci131/PROJECTS/PROJ1/model1.out.

    To submit your Finished Project:
    1. Submit your program file and your collaboration log (which should be named collaboration.txt) electronically using the submit program:

      ~csci131/bin/submit project1

    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
    Computer Science 131
    Last Modified: February 6, 2014
    Page Expires: September 2, 2014