Question

Write a C++ program and algorithm having two classes for determining a dot product and cross...

Write a C++ program and algorithm having two classes for determining a dot product and cross product of two vectors. Also find the angle between the vectors. Each vector size is 3D (x, y and z coordinates).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

  #include <bits/stdc++.h>
#define n 3
using namespace std;
int dotproduct(int vector_A[], int vector_B[])      // dot product of two vector array.
{
    int product = 0;
    for (int i = 0; i < n; i++)               // Loop for calculate dot product
        product = product + vector_A[i] * vector_B[i];
    return product;
}
void crossproduct(int vector_A[], int vector_B[], int cross_product[])       // cross product of two vector array.
{
    cross_product[0] = vector_A[1] vector_B[2] - vector_A[2] vector_B[1];
    cross_product[1] = vector_A[0] vector_B[2] - vector_A[2] vector_B[0];
    cross_product[2] = vector_A[0] vector_B[1] - vector_A[1] vector_B[0];
}
int main()
{
    int vector_A[] = { 2,3,4};
    int vector_B[] = { 5,6,7};
    int cross_product[n];
    cout << "Dot product:";
    cout << dotproduct(vector_A, vector_B) << endl;          // dotProduct function call
    cout << "Cross product:";
    crossproduct(vector_A, vector_B, cross_product);        // crossProduct function call
    for (int i = 0; i < n; i++)
                                cout << cross_product[i] << " "; // cross product of two vector array.
    return 0;
}

flow chat representation:-

Add a comment
Know the answer?
Add Answer to:
Write a C++ program and algorithm having two classes for determining a dot product and cross...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in c++ Write a program which can find the dot product of two vectors of the...

    in c++ Write a program which can find the dot product of two vectors of the same length ?. The user will enter the length ?. Use the length to control how many times you loop. The result is a scalar value and not a vector. If the dot product is zero, then the two vectors are perpendicular.

  • Vector A=5.0i+3.0j+4.0k and vector B=-2.0i+0.0j+4.0k. Find the dot product and cross product of vectors A and...

    Vector A=5.0i+3.0j+4.0k and vector B=-2.0i+0.0j+4.0k. Find the dot product and cross product of vectors A and B. What’s the angle between vectors A and B? Show that vectors A and B are perpendicular to their cross product (hint... use the dot product).

  • Problem 3 - Find the dot product between vectors A and B where Pa Worksheet 6 Vector Dot and Cross Products Problem 4...

    Problem 3 - Find the dot product between vectors A and B where Pa Worksheet 6 Vector Dot and Cross Products Problem 4 - Use the vector dot product to find the angle between vectors A and B where: Defining the Vector Cross Product: It turns out that there are some weird effects in physics that require us to invent a new kind of vector multiplication. For example, when a proton moves through a magnetic field, the force on the...

  • Simulation: Write a MIPS program which computes the vector dot product. Vector dot product involv...

    Simulation: Write a MIPS program which computes the vector dot product. Vector dot product involves calculations of two vectors. Let A and B be two vectors of length n. Their dot product is defined as: Dot Product-2.0 A(i): B(i) Where the result is stored in memory location DOTPROD. The first elements of each vector, A(0) and B(0), are stored at memory locations A_vec and B_vec, with the remaining elements in the following word locations Results: Put your MIPS code here...

  • C++: vectors. Euclidean vectors are sets of values which represent values in a dimensional field. A...

    C++: vectors. Euclidean vectors are sets of values which represent values in a dimensional field. A 2d vector would represent values in x,y space (an ordered pair of coordinates) and a 3d vector would represent values in x,y,z space (an ordered triplet of coordinates). We define the basic definition of the 2d vector as follows: class Vector2D { public: Vector2D (); Vector2D (double ,double ); double dotProduct(Vector2D& ); friend Vector2D& operator +(Vector2D&, Vector2D&); friend std::ostream& operator <<(std::ostream& o, Vector2D& a);...

  • Problem 3 - Find the dot product between vectors A and B where Pa Worksheet 6...

    Problem 3 - Find the dot product between vectors A and B where Pa Worksheet 6 Vector Dot and Cross Products Problem 4 - Use the vector dot product to find the angle between vectors A and B where: Defining the Vector Cross Product: It turns out that there are some weird effects in physics that require us to invent a new kind of vector multiplication. For example, when a proton moves through a magnetic field, the force on the...

  • NOT C++ Write a C function named dot_product to calculate the dot product of two vectors...

    NOT C++ Write a C function named dot_product to calculate the dot product of two vectors based on Formula 1. In the main C function, prompt the user to input two vectors, then call the function dot_product to find the dot product of those two inputted vectors. Remember to print out the result of the dot product.

  • Please answer all questions for UPVOTE LOCATION: Cleveland, Ohio DREAM LOCATION: Rome, Italy PRECALCULUS: VECTORS Directions: Suppose that you plan to take a trip to your dream destina...

    Please answer all questions for UPVOTE LOCATION: Cleveland, Ohio DREAM LOCATION: Rome, Italy PRECALCULUS: VECTORS Directions: Suppose that you plan to take a trip to your dream destination. You would like to know the shortest distance between your starting point and your destination. When calculating distances on a plane, you need only consider two dimensions because you are on a flat surface. However, when finding distances between two points on Earth, you must take into the account the curvature of...

  • Suppose and. a) Calculate dot (dot product) b) Find , where is the angle between the...

    Suppose and. a) Calculate dot (dot product) b) Find , where is the angle between the vectors and . Are and perpindicular? c) Find a vector P that is parallel to v and a vector N that is perpendicular to v such that

  • C++ Create a program that finds the dot product of two vectors. I'm currently trying to...

    C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT