Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

n C++ Remember from physics that given mass m and acceleration a, you can calcul

ID: 1421115 • Letter: N

Question

n C++ Remember from physics that given mass m and acceleration a, you can calculate force F using the formula F = ma. Further, remember that you can compute the components of a vector by using right triangles and trigonometry. If you forget how to find the horizontal or vertical component of a vector given an angle, draw right triangles to refresh yourself on this. Main Task - Function Writing: Your main task is to write a function that takes as parameters a mass, an acceleration, and an angle w.r.t. the horizontal. It should also take a fourth parameter that indicates a desire for a horizontal or vertical component. The function should compute either the horizontal or vertical component of the force vector described by the inputs. Begin by writing your function header, then write the PRE/POST, then write the body of this method. The angle must be input in degrees. Second Task - Function Testing: One of the big benefits of using methods is that we can break a large problem into smaller parts, where methods solve the smaller parts of the problem. Of course, if another method or a main program depends on a method, its important to make sure that the method works before using it. To that end, we usually write test drivers for methods, in other words, a main program that calls a method several times with various inputs and displays the outputs to see what results they give. Test drivers do not collect information from users; they are supposed to be quick and easy to re-run after each edit of the method. Write a test driver for your force function that makes at least four calls with hardcoded values; also include at least one call that calls your force function with arguments that are the values of variables local to main.

Explanation / Answer

#include // allows you to use std::cout to prompt to STDOUT using namspace std; // allows you to write cout and endl instead of std::cout std::endl /** * calculates the force using the formular force=mass*acceleration and returns the calculated force */ double calcForce(double mass, double acceleration, double angle, bool horizontal) { ... } /** "Driver" */ int main() { cout