Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete C++ assignment. Use vector3.cpp to implement the methods defined in vector3.h. Use main.cpp to test your vector In this exercise you will be

Please complete C++ assignment. Use vector3.cpp to implement the methods defined in vector3.h. Use main.cpp to test your vector

image text in transcribed

image text in transcribed

In this exercise you will be creating a 3-dimensional vector class in c+t. You will be provided with skeleton code that contains the required methods that must be implemented. Along with implementing the methods for the class, you are going to modifying the class so it is "const correct". Finally, you will be testing your implementation to ensure it is operating correctly The provided skeleton code has the following directory structure - CMakeLists.txt - main.cpp - vector3.cpp - vector3.h NOTE: DO NOT rename the files vector3.cpp or vector3.h, capitalization matters, or change the name of any of the methods contained within. If you do not use the skeleton code and start from scratch, make sure you name everything EXACTLY like it is in these two files. All of the method protypes you need to implement are defined in vector3.h. The only thing you should have to add to this file is the addition of 'const' to the appropriate methods. vector3.cpp is where you should implement the methods defined in vector3.h. main.cpp is where you should be testing your vector once you have implemented it. When we grade your code, we will be replacing your main.cpp with our own copy to verify your implementation's correctness. Therefore, it is very important that you do not rename things. Hopefully most of the required vector operations are familiar to you from previous math classes. One that will be unfamiliar is what is required for the increment and decrement operators. Rather than incrementing or decrementing anything, we are going to use them for "rotating" the vector's components. The increment operator will rotate to the left and the decrement operator will rotate to the right. Example: Vector3 a (5, 3, 2); Vector3 b-++a; Vector3 b will be (3, 2, 5), the values were "rotated" to the left. Vector3 c (5,3, 2); Vector3 d---c Vector3 c will be (2, 5, 3), the values were "rotated" to the right. Make sure when implementing these you remember the difference between pre and post increment/decrement. For submission, recompress the vec3 directory with your updated source files and submit via canvas. Appendix A: vector3.h pragma once include ciostreamp class Vector3 public Vector30 explicit Vector3(int xyzt Vectora(int , int y, int /set x, y and z to 0 /set x, y and z to xyz l/set component by name int get x0 int get yO: int get alb void set_xlint n) vaid set_ylint nyl void set fint nzh Vector3 operator (const Vector3&rhsWcomponent-wise add Vector3 operator (const Vector3&rhsk component-wise subtract Vector3 operator (const Vector3&rhs) /component-wise multiplication Vector3 operatorIconst Vector3&s llcomponent-wise division Vector3 operator (int rhsadd rhs to each component Vector3 operator-lint rhs); Vector3 operator(int rhs Vector3 operator int rhs) subtract rhs from each component /multiply cach component by rhs rWdivide each component by rh double operator(const Vector&hs dot product Vector3 operatora (const vector3& rts //cross product Vectors&operator (const Vector3&rhs component-wise add Vector&operaton const Vector&rhs; component-wise subtract Vector3&oator const Vector&rhs); /component-wise multiplication Vector3&operatorf-(const Vector&rh//component wise-division bool aperator-(const Vector3&rhs component-wise equality bool aperatort-(const Vector3&rhsh component-wise inequality double lengthl returns the length of the vector as a double Vectors get normalized /return a copy of this vector normalized Vector3+ and++Vector3 should rotate xyzto the left //i.e, make xsy.y : 1,1 Make sure they function correctly, + Vectori& operator+ Vectora operator int unused Vector3 and-Vector3 rotate xyz to the right lli.e. make x z,y=x,z-y Make sure they function correctly, wvvs Vector3& operator: Vector3 operaton (int unused private: int x inty, int z Vector3 operator+lint Ihs, const Vector3&rhs) Vectora operator (int lhs,canst Vector&rhst /For easy printing of vectors std:ostream&operatorstdzostream&os,const Vector&vec)

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

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions