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

Write a C program and save it as program6b.c that uses a structure, called Vecto

ID: 3559457 • Letter: W

Question

Write a C program and save it as program6b.c that uses a structure, called Vector, shown be a 3-dimesnional vector. Use this type definition (in the global scope, right below any #include's and #define's): Write the two functions with the following prototypes: The function dot_product implements the dot product of vectors where the dot product of a wad b is defined by the number: axbx + ayby + azbz The function cross_product implements the cross product of vectors where the cross product of a and b is defined by the vector c: cx = aybz - azby cy = azbx - azbz cz = axby - aybx Write the main function which prompts the user to enter values for each vector, then calculates and displays the cross product of the first times the second, the cross product of the second times the first, and the dot product of the two vectors, as shown in the sample run below. A sample run of your program should look like:

Explanation / Answer

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

typedef struct vector{
   int x;
   int y;
   int z;
}Vector;  

int dot_product(Vector a,Vector b){
   return (a.x)*(b.x) + (a.y)*(b.y) + (a.z)*(b.z) ;
  
}

Vector cross_product(Vector a,Vector b){
   Vector c;
   c.x = (a.y)*(b.z) - (a.z)*(b.y) ;
   c.y = (a.z)*(b.x) - (a.x)*(b.z);
   c.z = (a.x)*(b.y) - (a.y)*(b.x);
   return c ;
}

int main(){  
   Vector a,b,cross;
  
   cout<<"Enter the 3 integer components of the first vector";
   cin >>a.x>>a.y>>a.z;
  
   cout<<"Enter the 3 integer components of the second vector";
   cin >>b.x>>b.y>>b.z ;
  
   cross = cross_product(a,b) ;
   cout<<'('<<a.x <<' '<<a.y<<' '<<a.z<<')'<<" x "<<'('<<b.x<<' '<<b.y<<' '<<b.z<<") = (";
   cout<<cross.x<<' '<<cross.y<<' '<<cross.z<<')'<<' ';

   cross = cross_product(b,a);
   cout<<'('<<b.x<<' '<<b.y<<' '<<b.z<<')'<<" x "<<'('<<a.x <<' '<<a.y<<' '<<a.z<<") = (";
   cout<<cross.x<<' '<<cross.y<<' '<<cross.z<<')'<<' ';

   int dot = dot_product(a,b);
   cout<<'('<<a.x <<' '<<a.y<<' '<<a.z<<')'<<" . "<<'('<<b.x<<' '<<b.y<<' '<<b.z<<") = "<<dot<<' ';
  
    return 0;
}

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