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

I am not sure how to do this. Any help is much appreciated! I need to create a p

ID: 3626407 • Letter: I

Question

I am not sure how to do this. Any help is much appreciated!
I need to create a program that takes 4 rational numbers (floats or double based data type) representing the X and Y coordinates of two points respectively (X 1 , Y 1 then X 2 , Y 2 ) that represent a start and end point of travel (distance and direction, or VECTOR) between them. I need to compute the vector values and store them in a variable of a new data type.
The program must be able to run continuously (loop), entering the positional data, computing the new vector data, and displaying the results from the new data type you create until an appropriate end condition is met. The method by which you determine when data entry will stop is up to you but should not be so intrusive as to require the user to constantly intervene.

Also need to create a STUB function that takes the 4 parameter values as arguments, add a function call statement in your main program just after the existing computation statements.

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
// this is my program to compute a simple vector
double dX0 = 0.0, dX1(0.0), dY0 = 0.0, dY1 = 0.0;
double dMagnitude (0.0);
double dAngle = 0.0;

// Alternative to initialization
dX0 = dX1 = dY0 = dY1 = dMagnitude = dAngle = 0.0 ;

cout << "Enter the initial x,y values for point 0: ";
cin >> dX0 >> dY0;

int count = 0;
cout << "How many vectors will you compute? ";
cin >> count;

do
{
cout << "Enter the initial x,y values for point 1: ";
cin >> dX1 >> dY1;

// compute magnitude of vector
dMagnitude = sqrt( pow((dX1 - dX0), 2) + pow((dY1-dY0), 2) );

dAngle = atan( abs(dY0-dY1) / abs(dX0-dX1) );

cout << "The angle/direction of the vector is: " << dAngle << endl;
cout << "The magnitude of the vector is: " << dMagnitude << endl;

dX0 = dX1;
dY0 = dY1;

} while( --count > 0 );

system("pause");
return 0;
}

Explanation / Answer

"I need to compute the vector values and store them in a variable of a new data type." struct Vector { double dMagnitude; double dAngle }; A struct can be used to create a new datatype - in this case, the "Vector" datatype. I'd recommend changing the name from "Vector" to "vec" or something, because a vector is already a C++ datatype. For more info, see: http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/SYNTAX/struct.html do { cout > dX1 >> dY1; } while( --count > 0 ); Instead of storing them in dX1 and dY1, store the values in an array. This way, the only time the user has to input values is at the beginning. You can either create a 2-D array or create a struct for "other coordinate" and create an array of structs to store the value. Easiest solution: int coordinates[][] = new int[count][1] and stick "coordinates[count][0] = dX1; coordinates[count][1] = dX2" in your do-while loop. Then, you can use a separate loop to go through this array, calculate the values you need, print them, store in your vector struct, and you're done. What does your STUB function need to do?