Question: Your task in this homework assignment is to refactor a program using the struct construct to analyze and manipulate points. Solution Specifications Your solution to

Your task in this homework assignment is to refactor a program using the struct construct to analyze and manipulate points.

Solution Specifications

Your solution to this problem must meet the following criteria.

  1. Define two data structures, one for a cartesian point CartesianPoint and another for a polar point PolarPoint.
  2. Replace the code that uses (x,y) with code using a cartesian point structure.
  3. Replace the code that uses (r,t) with code using a polar point structure.
  4. When you can return a single structure from a function do so (rather than using pass-by-reference to get to multiple values).
  5. After updating the functions, the following should true about each function:
    • CartesianToPolar should take a cartesian point as a parameter and return a polar point.
    • PolarToCartesian should take a polar point as a parameter and return a cartesian point.
    • LengthC should take a cartesian point as a parameter and return a double.
    • NormalizedC should take a cartesian point point as a parameter and return a cartesian point.
    • DotProductC should take two cartesian points as parameters and return a double.
    • SumC should take two cartesian points as parameters and return a return a cartesian point.

You must product output matching the existing output, but change the internals of the code.

USING C++ LANGUAGE: In file main.cpp

Your task in this homework assignment is to refactor a program using

IN file points.cpp

the struct construct to analyze and manipulate points. Solution Specifications Your solution

In file points.h

to this problem must meet the following criteria. Define two data structures,

Edit points.cpp and possibly points.h for struct construct

#include "points.h" * /*==================================================================== * Main program */ int main() { double x1 = 1.0, y1 = 2.0; cout // for cin and cout #include // for trig functions using namespace std; #include "points.h" void CartesianTopolar(double x, double y, double &radius, double &theta) { radius = sqrt(pow(x, 2) + powly, 2)); theta = atan2(y, x); 20 void PolarToCartesian(double radius, double theta, double &x, double &y) { x = radius * cos(theta); y = radius * sin(theta); } 26 double Lengthc(double x, double y) { return (sqrt(pow(x, 2.0) + powly, 2.0))); } void Normalizedc(double xIn, double yIn, double exOut, double &yout) { double length = Length (xIn, yin); xOut = xin / length; yout = yIn / length; } 34 35 36 double DotProductC(double firstx, double firsty, double secondx, double seconde) { return (firstx * secondx + firsty * seconde) } 39 void Sumc(double firstx, double firsty, double secondx, double seconde, double &resultx, double &resulty) {/ resultx = firstx + secondx; resulty = firsty + secondy: } 44 45 #ifndef POINTS_H #define POINTS_H // function declarations (prototypes) void CartesianToPolar(double x, double y, double &radius, double &theta); void PolarToCartesian(double radius, double theta, double &x, double &y); double Lengthc(double x, double y); void Normalizedc(double xIn, double yin, double &xOut, double &yout); double DotProductc(double firstx, double firsty, double secondx, double seconde); void Sumc(double firstx, double firsty, double secondx, double seconde, double &resultx, double &resulty); 21 24 #endif // POINTS_H 25

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!