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

In vector algebra we define a three dimensional vector v to be a on ordered trip

ID: 3573438 • Letter: I

Question

In vector algebra we define a three dimensional vector v to be a on ordered triple v = (x, y, z) where x, y and z are real numbers.

We also define vector addition to be component wise this means that : If v = (s, t, u) and w = (x, y, z) then v + w = (s+x, t+y, u+z).

1. Create a new vector class in C++ that has a constructor that initializes its instances to (0, 0, 0).

2. Add a set Components function that will mutate (modify) the vector instance and set its components to the three parameters x, y, z passes to the function respectively.

3. Add an add function add(v) that adds v to the current vector.

4. Add a display function that displays the vector as triple (x, y, z)

5. Write a main function that creates two instances and correctly add them display all three vectors.

//Please help me with the following too which is a continuation!

6. Overload the + symbol to become vector addition.

7. Overload the rational == to yield true if v and w has the same length.

8. Write a generic function that calculates the length for an arbitrary “measurable” type using If v = (s, t, u , ... ,) Then length(v) = s2 + t2 + ... Meaning that the length is the square root of the sum of the components squared

9. Write a main function that creates two instances and correctly add using + and =, display all three vectors and the length of each of the three vectors

Explanation / Answer

#include<iostream>
using namespace std;
//class definition
class vector
{
int x,y,z;//private and thus not accessible by non member function
public:
vector()
{
x=0;y=0;z=0;//it initializes x=y=z=0 this is contructor definition
}
void setcomponents(int r,int s,int t)
{
x=r;y=s;z=t; //sets x,y,z according to passed parameters
}

void add(vector v)
{
vector w;
w.x=x+(v.x);w.y=y+(v.y);w.z=z+(v.z); //this adds the passed and current parameters of class vector and stores to the third vector
cout<<"sum is ("<<w.x<<","<<w.y<<","<<w.z<<")"<<endl;//prints the sum
}
void display()
{
cout<<"vector is ("<<x<<","<<y<<","<<z<<")"<<endl;//displays vector
}

};

int main()
{
vector n,m;//creating instances
n.setcomponents(2,3,4);m.setcomponents(1,4,5);//setting x,y,z to passed parameters
n.display();m.display(); //and displays
n.add(m); //adds
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