|Assigned||18 Jan 2017 @ 01:17h|
|Due||23 Jan 2017 @ 23:59h|
Implement a function that has been declared for you but not defined.
Given the following declaration:
/** * Calculates the time required for an accelerating object to reach a * particular distance. * * @param a the (constant) acceleration of the object [m/(s*s)] * @param v initial velocity [m/s] * @param d final displacement [m] * * @returns the (positive) time required to reach displacement `d` */ double accelTime(double a, double v, double d);
accelTime function in a file called
You may find it helpful to know that there is a function called
declared in the
cmath header file that calculates a square root when passed
a real number as an argument.
The top-level result for this assignment was that over half of the submissions I received earned full marks on the functional evaluation (the TAs will also grade for style, but that will take a little longer to complete). As you can see from the graphs above, several submissions would not compile due to syntactic errors, and a few people submitted files that were not C++ source files (instead they were, e.g., zip files). I’ve detailed some of the common errors that I saw below.
accelTime(-9.8, 10, 1), it depends on the contract established on the assignment page. This includes the order of parameters for the
accelTimefunction: first acceleration, then initial velocity, then displacement. If you change the order of these parameters then the wrong values will end up in the wrong place.
(-v + sqrt(v*v + 2*a*d)) / ain C++, where
vis initial velocity and
ddisplacement. An incorrect expression could lead to simply incorrect values or something more dramatic like calculating the square root of a negative number, which will yield a result of
nan(“not a number”).
accelTimefunction was not defined in the submitted source file. For example, if you didn’t implement
accelTimebut instead just did some calculations in
mainand printed the result, then my test code, looking for an
accelTimefunction, would fail to build. If the missing function was due to a more trivial error like a misspelling of the function name (
accelTime), please come see me and we can talk about possible resolutions.
#include <iostream>or else
using namespace stdat the top of your source file. This omission should’ve been caught when you tried to compile the code on your own computer… if it wasn’t, perhaps you could come see me to talk about it.
#include <cmath>in your source file before you called the
sqrtfunction. As I mentioned on the assignment page, the
sqrtfunction is declared in the
cmathheader file, so you must
#include <cmath>before you can use it.