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

Create a program in c++ using vectors in R3 (3D vectors) that will be used to ca

ID: 3917041 • Letter: C

Question

Create a program in c++ using vectors in R3 (3D vectors) that will be used to calculate the volume of a parallelepiped. The volume of a parallelepiped determined by the vectors a, b and c is the absolute value of the scalar triple product:

v = | a x (b x c) |, where b × c is the cross product of b and c, and a x (b ×c) is the dot product of a and the cross product of b and c.

1. Create a void function named input that will receive a vector and load the integer coordinates of a 3D vector. Use this function to load the three vectors va, vb, vc.

2. Create a function named dotproduct that will receive two 3 dimensional vectors and return their dot product. (This function returns an integer)

3. Create a function named crossproduct that will receive two 3 dimensional vectors and return their cross product. (This function returns a vector)

4. Using parts 2 and 3 and the formula above calculate the volume of the parallelepiped and output the appropriate message:

The volume of object is: #

5. Create an outer loop to let the user continue calculating the volume of new vectors.

Would you like to continue? Y, N

Formulas for dot and cross products

If a and b are vectors a = <a1,a2,a3>,b= <b1,b2,b3>, then

Dot Product: a x b = a1b1 + a2b2 + a3b3,

Cross product: a × b= < a2b3 - a3b2,a3b1 - a1b3,a1b2 - a2b1 >

Note: Dot product returns an integer and the cross product returns an integer vector.

6. Test your program with the values below:

Expected output for each of the values required:

Vectors: va = <1,-2,3> vb = <4,3,0> vc = <9,2,-3> Volume: 90

Vectors: va = <4,0,-1> vb = <2,2,7> vc = <0,1,6> Volume: 18

Vectors: va = <5,5,-3> vb = <-2,1,1> vc = <7,0,0> Volume: 56

Explanation / Answer

#include<iostream>

using namespace std;

typedef struct vector{

int x,y,z;

}vector;

void input(vector*v){

cout<<"Enter 3-D vector : ";

cin>>v->x>>v->y>>v->z;

}

int dot_product(vector*v1,vector*v2){

return (v1->x*v2->x)+(v1->y*v2->y)+(v1->z*v2->z);

}

vector* cross_product(vector*v1,vector*v2){

struct vector *v=new vector;

v->x=(v1->y)*(v2->z)-(v1->z)*(v2->y);

v->y=(v1->x)*(v2->z)-(v1->z)*(v2->x);

v->z=(v1->x)*(v2->y)-(v1->y)*(v2->x);

return v;

}

int main(){

vector *v1,*v2,*v3,*v;

v1=new vector;

v2=new vector;

v3=new vector;

char choice;

do{

input(v1);

input(v2);

input(v3);

v=cross_product(v2,v3);

int volume=dot_product(v1,v);

cout<<"volume is : "<<volume<<" ";

cout<<"do you want more (y/n) : ";

cin>>choice;

}while(choice=='y');

return 0;

}

/*for any query please comment.

please upvote if find it helpful.

Thank you.*/

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