CS 010 - Introduction to Computer Science I
Assignment 6:

DUE: Fri. May 20th before 2:00pm


Collaboration Policy

Limited collaboration is OK. You may do the following while writing a programming assignment: discuss general solution ideas with your study group members or have members observe a run of your program, and offer their ideas on its behavior. You should *never* look at someone else's code for the assignment to figure out how to do your own program. It is very hard to write your own unique solution once you have seen someone else's. If you need someone to look at your code to give advice, you should see your TA or instructor. Of course, copying code from ANY source (any book, current or past student, past solutions, or the web) is STRICTLY FORBIDDEN.


Code that is turned in, must be contained in a .cpp file named main.cpp. Files of any other format will not be graded (e.g. main.doc, main.txt, etc…).

You must turn your work in from a lab computer on campus.

Turn in online to as6 folder. If you turn your assignment in to the wrong folder, your assignment may not be graded. If it is graded, you will lose 20 pts (out of 100).

Programs that do not compile will receive a 0 out of 100!

Programs that do not have the readme file turned in with the main.cpp file will not be graded.

Remember to include the following header information at the top of your program;

// Course: CS 10
//
// Lecture Section: ... 001 or 002
// Lab Section: ... 021, 022, etc)
//
// Assignment #: ... assignment 2, 3, etc.
//
// Last Name: Enter your LAST (family) name here (eg, Doe)
// First Name: Enter your FIRST (given) name here (eg, John)
//
// ID Number: Enter your ID number here (eg, 860-00-0000)
// lab login id: Enter your cs10 login here (eg, jdoe)
//
// Email address: Enter your UCR email address here (eg, jdoe@cs.ucr.edu)

// =======================================================================




Problem Definition:

    For this assignment you will write 3 functions; two that return values and are passed value parameters, and one that returns void and is passed reference parameters.  You will also have to add some lines of code that are missing from ccc_win_main().  The values calculated in the functions will be used in a control algorithm.  The control algorithm simulates a body falling under the force of gravity, and with the capability to produce vertical, and horizontal "thrust" through a rocket engine.  For this assignment, you will not need to draw a ship, you will just move a point around, and draw a circle around this point.  The code needed to impliment the control algorithm--including animation--has been partially written, and is contained in the file below.
    You will need to write three function definitions; a function that returns a new position based on the current position, velocity, acceleration, and time, a function that returns a new velocity based on the current velocity, acceleration, and time, and a function that assigns a vertical, and horizontal acceleration value based on the user's input.  Since the last function is assigning two values, it should return void, and assign the two values to reference variables in the parameter list that is passed to it.
    You should pass the correct values to each function from ccc_win_main, and declare the correct type for each variable in the function header.

To calculate the position you will use the equation:
pos_new = pos_initial + t * vel_initial + 0.5 * t * t * acceleration

To calculate the velocity you will use the equation:
v_new = v_initial + acceleration * t

For all equations above, "t" is the current time step value.

The value assigned in the acceleration function to the reference variables will depend on the user's selection for the thrust:
Vertical/Main Thruster:
(l)ow = "l" = 0
(h)igh = "h" = 1
(n)one = "n" = -1

Horizontal, Right Thruster (on right side of circle, pushing circle left):
(l)ow = "l" = -0.5
(h)igh = "h" = -1
(n)one = "n" = 0

Horizontal, Left Thruster (on left side of circle, pushing circle right):
(l)ow = "l" = 0.5
(h)igh = "h" = 1
(n)one = "n" = 0


    The Final value for the horizontal thrust will be the sum of the right and left thrust.
    In the body of the ccc_win_main function, you will need to add code to the while loop.  A numbered comment indicates where the lines of code needs to be added.  For each numbered comment in the loop, add only the specified number of lines of code.  Failure to add the specified amount(s) will result in loss of points.  All the variables you will need have been declared in ccc_win_main before the while loop, and you can ONLY use these variables in the lines of code that you add.

IMPORTANT NOTES!
    The constant "UPDATE_SCREEN" controls how often the time "t" variable for the circle is increamented, thus how often the circle moves on the screen. On slower computers this should be set to a smaller value than given, but on faster computers this should be set to a bigger value. You might have to do some *tweaking* to this value to get your animation to look smooth.
    Also, the program does not naturally terminate, so you must type <control-c> from the terminal to close the graphics window.

Hints:
1) One of the hardest things to figure out in this program is what variables to pass to the functions.  First, figure out which variables to pass to the set position function in the UPDATE_SIM if statement. Next, figure out which variables you should pass to the set position function outside the UPDATE_SIM if statement. There is a reason that there is one variable called "current_(x, or y)", and another called "init_(x, or y)", you will need to use both.
2) If you can only get your program to run like the example program by changing the value of UPDATE_SIM, you probably (99.9999%) didn't figure out the correct variables to pass to the functions in lines 2, 3, 4, and 7.

Starting Code
main.cpp

Example Program Download
main


Rubric: (100 pts total)

10 pt: Correct function header for position function, and return type
10 pt: Correct function header for velocity function,
and return type
10 pt: Correct function header for acceleration function,
and return type
40 pt: Added correct lines of code for comments 2, 3, 4, and 7
10 pt: Added correct lines of code for other comments
5 pt: Only specified number of lines of code for each numbered comment
5 pt: No variables/constants were added to the program (used variables that were already declared in ccc_win_main)
10 pt: Style
- Good variable names
- Proper indentation and spacing
- Good comments
- No line wraps
- No magic numbers
- Header info included

Note that you can also receive penalties for this assignment. See the top of this page for details.

Fill out the following form, and turn it in with your program:
readme.txt

For coding style requirements see the following link:
http://www.cs.ucr.edu/cs10/cs10_05win/requirements/coding_std.html