Question: The Main function: Write a main that performs that tasks below. A simplifying assumption is that all user inputs are valid and that all the
The Main function:
Write a main that performs that tasks below. A simplifying assumption is that all user inputs are valid and that all the expressions are defined.
1. Your program will prompt the user for the dimension and coordinates of three vectors, say v1, v2, and v3. Your program will then dynamically allocate three arrays to represent the three vectors as three arrays in dimension-coordinates format using these values entered by the user.
2. Your program will then display v1, v2, and v3.
3. Your program will compute and display v1 + v2.
4. Your program will compute and display (v2 + v3) v1 and |v1 v3|.
5. Your program will compute and display v1 v2 and |v2| |v1|.
6. Your program will prompt the user for three 3-dimensional vectors, say v4, v5, and v6. Your program will then display these vectors. Using these vectors, your program will compute and display the remaining vector expressions.
7. Your program will compute and display v4v5 |v1v5| .
8. Your program will compute the unit vector of v4 v5, v\4 v5.
9. Your program will compute and display v4 (v5 + v6).
10. Your program will compute and display (v4 v5) + (v4 v6).
11. Finally, using the equal function, your program will determine whether or not the vectors calculated in 9 and 10 are equal
In addition to the main, your program should consists of the following functions:
/**
* Give the dimension of the specified vector
* @param v a vector in dimension-coordinates format
* @return the dimension of this vecot
*/ int dim(const double v[])
/**
* Gives a string representation of this vector in the form
* , where x1 is the second element of the array,
* x2, the second element of the array, etc and n is the dimension
* of the vector and the first element of the array.
* @param v a dimension-coordinates array representation of a
* vector.
* @return a string representation of the specified vector
*/ string vectToString(const double v[])
/**
* Gives a coordinate with the specified subscript of a vector
* @param v a dimension-coordinates array representation of a
* vector
* @param subscript a subscript of a coordinate of the vector
* @return the specified coordinate of v or NAN when
* subscript
*/ double getCoordinate(const double v[], int subscript)
/**
* Computes the length of this vector
* @param v a dimension-coordinates array representation of a
* vector
* @return the length of the specified vector
*/ double length (const double v[])
/**
* Determines whether two vectors are equal; two vectors are
* equal if they have the same dimension and their
* corresponding coordinates are equal.
* @param v1 a vector
* @param v2 a vector
* @return true if the specified vectors are equal;
* otherwise, false
*/ bool equal(const double v1[], const double v2[])
/**
* Computes the unit vector of the specified vector
* @param v a vector
* @return the unit vector of the specified vector
*/ double
* unit(const double v[])
/**
* Computes the sum of the specified vectors
* @param v1 a vector
* @param v2 a vector
* @return the sum of the specified vectors if they have the same
* dimension or NULL, otherwise
*/ double
* add(const double v1[], const double v2[])
/**
* Computes the difference of the specified vectors
* @param v1 a vector
* @param v2 a vector
* @return the v1-v2 if the vectors have the same
* dimension or NULL, otherwise
*/ double
* sub(const double v1[], const double v2[])
/**
* Computes the dot product of two vectors
* @param v1 a vector
* @param v2 a vector
* @return the dot product of v1 and v2 if they have the same
* dimension; otherwise, NAN
*/ double dot(const double v1[], const double v2[])
/**
* Computes the cross product of two 3-D vectors
* @param v1 a vector
* @param v2 a vector
* @return the cross product of v1 and v2 if they are both
* 3-dimensionsional vectors; otherwise, NULL
*/ double
* cross(const double v1[], const double v2[])
/**
* Computes the product of a vector and a number (scalar)
* @param v a vector
* @param n a number
* @return a vector whose coordinates are those of v, each
* multiplied by n; that is,
*/ double
* mult(const double v[], double n)
in C++
A typically run of the program would be Listing 1: Code Segment 1 Sample Run: 2 Enter the dimension of three vectors - 4 3 Enter the coordinates of v1 -> 1 2 3 4 4 Enter the coordinates of v24 1 2 3 5 Enter the coordinates of v32 3 4 1 7 v1 = v2 = 9 v3 = 10 12 v1 v2 13 (v2 + v3) * v1 48 14 lv2 - V3! = 3.4641 15 v1*224 and v2 v130 16 17 Enter three 3-D vectors 18 Enter v41 2 3 19 Enter v5-3 1 2 20 Enter v62 3 1 21 22 v4 23 v5 = 24 v6 25 26 (v4 x v5) / (lv4 x v5!) = 27 unit (v4 xv5) = 28 29 v4 x (v5 + v6) = 30 (v4 x v5) + (v4 x v6) 31 v4 x (v5 + v6) and (v4 x v5) (v4 x v6) are equl A typically run of the program would be Listing 1: Code Segment 1 Sample Run: 2 Enter the dimension of three vectors - 4 3 Enter the coordinates of v1 -> 1 2 3 4 4 Enter the coordinates of v24 1 2 3 5 Enter the coordinates of v32 3 4 1 7 v1 = v2 = 9 v3 = 10 12 v1 v2 13 (v2 + v3) * v1 48 14 lv2 - V3! = 3.4641 15 v1*224 and v2 v130 16 17 Enter three 3-D vectors 18 Enter v41 2 3 19 Enter v5-3 1 2 20 Enter v62 3 1 21 22 v4 23 v5 = 24 v6 25 26 (v4 x v5) / (lv4 x v5!) = 27 unit (v4 xv5) = 28 29 v4 x (v5 + v6) = 30 (v4 x v5) + (v4 x v6) 31 v4 x (v5 + v6) and (v4 x v5) (v4 x v6) are equl
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
