CMPSCHWK1 - z.Implement the default and copy...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
50 points: Create a vector structure with three member components - x, y, and z of type double. Create a function that takes as input a single const parameter of type vector and returns the magnitude of the vector (remember the magnitude of a vector is the square root of x*x + y*y + z*z). Create a function take takse as input 2 const parameters of type vector and returns their vector sum. (remember that adding vectors is done component-wise - that is, the sum vector's x component is equal to the sum of the x components of the input vectors, etc. ..) Write the main program to declare several vectors, initialize them with some values, and show that the two functions work properly by calling them and displaying the results. Redo the above using classes. Create a Vector class containing three protected data members, x,y and
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: z.Implement the default and copy constructors.Provide accessor methods (getters and setters) for the three data members. Implement the magnitude function as a public member method. Implement these global friend functions: ostream& operator<<(ostream& o, const Vector& v); Vector operator+(const Vector& v1, const Vector& v2); Vector operator-(const Vector& v1, const Vector& v2); Extra Credit opportunity 1 (10 points): Implement operator+=, operator-=, operator* between a Vector and a double, operator/ between a Vector and a double (there are two orderings each for * and / ) Extra Credit Opportunity 2 (10 points): The dot product P of two Vectors v1 and v2 is defined as follows: P = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z...
View Full Document

Ask a homework question - tutors are online