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

Write a program that performs basic vector operations as follows. The user shoul

ID: 3646213 • Letter: W

Question

Write a program that performs basic vector operations as follows. The user should first input two 3D vectors (px, py, pz) and (qx, qy, qz). They should then input one of the four following symbols to indicate which of the following operations they wish the program to perform on the vectors: + (addition), - (subtraction), . (dot product), x (cross product).


1. Use a multiple alternative if statement to decide between the operations and display the result. If the user enters an invalid symbol the program should display an error message (note: this should be part of the if statement). Put the if statement inside a while loop or do loop that asks if the user wants to do another operation. If so, the user responds with a 'y' or 'Y'. If not, the user responds with a 'n' or 'N'.


2. Copy your program to another file and then modify the new file so that the multiple alternative if statement is replaced by a switch statement.

Explanation / Answer

/* Return the inner product of two input vectors */ double vl_dot3( double *v1, /* Input vector 1 */ double *v2); /* Input vector 2 */ /* Scale a 3d vector void vl_scale3( double fact, /* double *v1, /* double *v2); /* /* Return length of a 3d vector */ double vl_length3( double *v1); /* Vector whose length is desired */ /* Compute the difference of two vectors */ /* v3 = v2 - v1 */ void vl_diff3( double *v1, /* subtrahend */ double *v2, /* minuend */ double *v3); /* result */ /* Compute the sum of two vectors void vl_sum3( double *v1, /* addend double *v2, /* addend double *v3); /* result /* Construct a unit vector in direction of input */ void vl_unitvec3( double *v1, /* Input vector */ double *v2); /* Print a label and the contents of a vector */ void vl_vecprn3( char *label, double *vec); */ Scale factor */ Input vector */ Output vector */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote