Question

In: Computer Science

C++ Suppose the vector v = [4 -6 7]. Create three vectors: 1. p, which is...

C++

Suppose the vector v = [4 -6 7]. Create three vectors:

1. p, which is twice as long as v and points in the same direction as v
2. q, which has the same length as v and points in the opposite direction of v
3. r, which is three quarters the length of v and points in the same direction as v
Print out the results of each vector calculation.

Solutions

Expert Solution

#include <iostream>
using namespace std;

void printVector(float vector[]) {
for (int i = 0; i < 3; i++)
cout << vector[i] << " ";
cout << endl;
}

void multiplyVector(float vector[], float multiplier) {
float* p = new float[3];
for (int i = 0; i < 3; i++)
p[i] = vector[i] * multiplier;
  
printVector(p);
}

void doubleVector(float vector[]) {
multiplyVector(vector, 2.0f);
}

void reverseVector(float vector[]) {
multiplyVector(vector, -1.0f);
}

void threeQuarterVector(float vector[]) {
multiplyVector(vector, 3.0f/4.0f);
}

int main() {
   //vector v
   float v[3] = {4, -6, 7};
   cout << "Vector v: ";
   printVector(v);
  
   //vector p
   cout << "Vector p: ";
   doubleVector(v);
  
   //vector q
   cout << "Vector q: ";
   reverseVector(v);
  
   //vector r
   cout << "Vector r: ";
   threeQuarterVector(v);
  
   return 0;
}

=======Output========

Vector v: 4 -6 7
Vector p: 8 -12 14
Vector q: -4 6 -7
Vector r: 3 -4.5 5.25


Related Solutions

C++ Vectors. Create a program do the following in the program: 1. declare an vector without...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without specifying the size 2. use push_back to add random integers between 100 and 999 to the vector 3. write a function that returns the smallest, largest, and average of the numbers in the vector display the smallest, largest, and average of the numbers in the vector
Given vector s = [4, -5, 7], u = [-6, 8, 11], and v = [-5,...
Given vector s = [4, -5, 7], u = [-6, 8, 11], and v = [-5, 3, -7] a. Let r1(t) be the vector equation through s and u. Express the vector equation r(t) in two ways and then find r(1); r(-5); r(9) b. Let r2(t) be the vector equation through u and parallel to r1(t), Express r2(t) in two forms and then find r(-3); r(13); r(2) c. Let w = 2s -4v, find r(t) through u and v
Suppose u, and v are vectors in R m, such that ∥u∥ = 1, ∥v∥ =...
Suppose u, and v are vectors in R m, such that ∥u∥ = 1, ∥v∥ = 4, ∥u + v∥ = 5. Find the inner product 〈u, v〉. Suppose {a1, · · · ak} are orthonormal vectors in R m. Show that {a1, · · · ak} is a linearly independent set.
Create a function that takes a vector of vectors as an argument. Each inner vector has...
Create a function that takes a vector of vectors as an argument. Each inner vector has 2 elements. The first element is the numerator and the second element is the denominator. Return the sum of the fractions rounded to the nearest whole number. Examples: sum_fractions({{18, 13}, {4, 5}}) ➞ 2 sum_fractions({{36, 4}, {22, 60}}) ➞ 9 sum_fractions({{11, 2}, {3, 4}, {5, 4}, {21, 11}, {12, 6}}) ➞ 11 Notes Your result should be a number not string. Code in C++...
(1) Suppose that V is a vector space and that S = {u,v} is a set...
(1) Suppose that V is a vector space and that S = {u,v} is a set of two vectors in V. Let w=u+v, let x=u+2v, and letT ={w,x} (so thatT is another set of two vectors in V ). (a) Show that if S is linearly independent in V then T is also independent. (Hint: suppose that there is a linear combination of elements of T that is equal to 0. Then ....). (b) Show that if S generates V...
A basis of a vector space V is a maximal linearly independent set of vectors in...
A basis of a vector space V is a maximal linearly independent set of vectors in V . Similarly, one can view it as a minimal spanning set of vectors in V . Prove that any set S ⊆ V spanning a finite-dimensional vector space V contains a basis of V .
Define a subspace of a vector space V . Take the set of vectors in Rn...
Define a subspace of a vector space V . Take the set of vectors in Rn such that th coordinates add up to 0. I that a subspace. What about the set whose coordinates add up to 1. Explain your answers.
Three vectors A, B and C are related via A+B=C. Which of the following diagrams illustrates these vectors?
Three vectors A, B and C are related via A+B=C. Which of the following diagrams illustrates these vectors?
Three vectors A, B and C are related via B+C = A. Which of the following diagrams illustrates these vectors?
Three vectors A, B and C are related via B+C = A. Which of the following diagrams illustrates these vectors? 
Three vectors are given as A=<3.5, -5.3, 1.1> B=<4.5, 7.5, -7> C=<-3.9, 4.8, -6> a) Determine...
Three vectors are given as A=<3.5, -5.3, 1.1> B=<4.5, 7.5, -7> C=<-3.9, 4.8, -6> a) Determine the angle between A and B. b) Determine the angle between A and C c) Compute the dot product of B and C d) Determine the size of the area associated with vectors B and C. e) Determine the quantity (B (dot)(A(cross)C))
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT