Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. Dot Product Let v and w be two n-dimensional vectors. Their dot product is the sum of the products of their respective components. For

A. Dot Product

Let v and w be two n-dimensional vectors. Their dot product is the sum of the products of their respective components. For example, if n is 4, v is the vector (1, 0, 2, 1) and w is the vector (?1, 2, 1, 4), then their dot product is 1 (?1) + 0 2 + 2 1 + 1 4 = 5.Write a C++ program that does the following:

Has the user to input an integer n.

Dynamically allocates two n-dimensional vectors of doubles.

Has the user input the components for the two vectors.

Computes and prints out the dot product.

Deletes the two vectors.

All the steps above should be in a continuation loop, so the user can repeat the process as many times as he or she wishes.

Here is an example of program input and output:

Enter number of components per vector: 2 Enter components for v: 2.1 1.0 Enter components for w: 2.0 1.2 Dot product: 5.4 
Compute another dot product (y/n)? y Enter number of components per vector: 4 Enter components for v: 1 2 3 4 Enter components for w: 2 3 2 -1 Dot product: 10 Compute another dot product (y/n)? n 

Here are a few comments/reminders: You must dynamically allocate the vectors.

Remember to delete the vectors at the end of each iteration of the continuation loop.

You may assume that all the input is valid. For example, you do not need to check whether the value that the user inputs for n is a positive integer.

Make sure your output follows the format in the example.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

7.2 Explain the selection process.

Answered: 1 week ago