c++ PE04 - Functions and Prototypes For this exercise, you'll complete two problems. Problem 1 - Function Declarations Write the prototypes for several function calls, deducing the correct signature from the context in PrototypeTester.cpp Do not implement the functions themselves. That is already done. Place the prototypes in pe04.h. Problem 2 - Write a Function Write a function named quadratic() which computes roots of quadratic equations. Recall that a quadratic equation is one of the form, ax2 + bx + c = 0. Your function accepts five arguments: The integer coefficients a, b, and c as three input parameters. Two real number (double) output parameters root1 and root2. Your function should compute the two roots of the quadratic equation and store them into the two output parameters. For example, the equation x2 - 3x - 4 = 0 has roots of x = 4 and x = -1, so the call: double root1, root2; quadratic(1, -3, -4, root1, root2); should set root1 to 4.0 and root2 to -1.0. You may assume that the function has two real roots. Recall that the quadratic formula is: Constraints: You should not use any built-in functions from the system libraries except for sqrt() from the header. You must program this function by "hand". pe04.h #ifndef PE04_H #define PE04_H #include // PLACE YOUR PROTOTYPES BELOW THIS LINE // PUT YOUR PROTOTYPES ABOVE THIS LINE #endif Use this following file: PrototypeTester.cpp #include #include #include #include "checker.h" using namespace std; #include "pe04.h" int main() { // A. --------------------------------------------------------- cout << defined(true, 3.5, "Hello", 75) << endl; // prints 150 cout << "Expected: 150" << endl; // B. --------------------------------------------------------- string v = "p1.cpp"; bool okA; double x; int ba = 5; cout << compile(v, okA, ba, x) << endl; cout << "Expected: 12.5" << endl; // changed->okA->true, x->2.5, v not changed, ba not changed // C. --------------------------------------------------------- cout << seekDir(2.5, 'x') << endl; // prints 0.0 cout << "Expected: 0.0" << endl; // D. --------------------------------------------------------- bool okB = false; cout << closeDir(2.5, 'x', okB) << endl; cout << "Expected: 5" << endl; // prints 5, okB->true // E. --------------------------------------------------------- bool okC; long long seekPos = 107LL; const string POS_NAME = "CUR_DIR"; cout << rewindDir(POS_NAME, okC, 1.5, seekPos) << endl; cout << "Expected: X" << endl; // prints 'X', okC->true, seekPos->102LL } pe04.cpp #include using std::sqrt; // Write your function here
c++
PE04 - Functions and Prototypes
For this exercise, you'll complete two problems.
Problem 1 - Function Declarations
Write the prototypes for several function calls, deducing the correct signature from the context in PrototypeTester.cpp Do not implement the functions themselves. That is already done. Place the prototypes in pe04.h.
Problem 2 - Write a Function
Write a function named quadratic() which computes roots of quadratic equations. Recall that a quadratic equation is one of the form, ax2 + bx + c = 0.
Your function accepts five arguments:
- The integer coefficients a, b, and c as three input parameters.
- Two real number (double) output parameters root1 and root2.
Your function should compute the two roots of the quadratic equation and store them into the two output parameters. For example, the equation x2 - 3x - 4 = 0 has roots of x = 4 and x = -1, so the call:
double root1, root2; quadratic(1, -3, -4, root1, root2);
should set root1 to 4.0 and root2 to -1.0.
You may assume that the function has two real roots. Recall that the quadratic formula is:
Constraints: You should not use any built-in functions from the system libraries except for sqrt() from the <cmath> header. You must program this function by "hand".
pe04.h
// PLACE YOUR PROTOTYPES BELOW THIS LINE
// PUT YOUR PROTOTYPES ABOVE THIS LINE
#endif
Use this following file:
PrototypeTester.cpp
#include <iostream> #include <string> #include <vector> #include "checker.h" using namespace std; #include "pe04.h" int main() { // A. --------------------------------------------------------- cout << defined(true, 3.5, "Hello", 75) << endl; // prints 150 cout << "Expected: 150" << endl; // B. --------------------------------------------------------- string v = "p1.cpp"; bool okA; double x; int ba = 5; cout << compile(v, okA, ba, x) << endl; cout << "Expected: 12.5" << endl; // changed->okA->true, x->2.5, v not changed, ba not changed // C. --------------------------------------------------------- cout << seekDir(2.5, 'x') << endl; // prints 0.0 cout << "Expected: 0.0" << endl; // D. --------------------------------------------------------- bool okB = false; cout << closeDir(2.5, 'x', okB) << endl; cout << "Expected: 5" << endl; // prints 5, okB->true // E. --------------------------------------------------------- bool okC; long long seekPos = 107LL; const string POS_NAME = "CUR_DIR"; cout << rewindDir(POS_NAME, okC, 1.5, seekPos) << endl; cout << "Expected: X" << endl; // prints 'X', okC->true, seekPos->102LL }
pe04.cpp
#include <cmath>
using std::sqrt;
// Write your function here
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images