Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the definition for a class named Vector2D that stores information about a two-dimensional vector. A 2D vector has both an x component in the

Write the definition for a class named Vector2D that stores information about a two-dimensional vector. A 2D vector has both an x component in the direction and a y component in the direction The class should include appropriate constructor(s) and have methods to get and set the xcomponent and the y component, where x and y are double type. The class should also include a method that computes and returns the magnitude of the vector, where the magnitude is computed as . Your class should also include a method to print a vector in the form: 3i + 4jimage text in transcribed

Write the definition for a class named Vector2D that stores infomation about a two dimensional vector. A 2D vector has both omponent in the i direction and a y component in the j direction. For example: A 2 4 5 The class should include appropriate constructor(s) and have methods to get and set the x component and they component, wherexandy are double type. The class should also include a method that computes and returns the magnitude ofthe vector, where the magnitude is computed as Vx2 y2. Your class should also include a method to print a vector in the form: 3i 4j (where i stands for i and j for j). Aiote: declare magnitude as a const function. why?) Next, overload the following Binary operators (note: boolean operators retum false if not true) Addition: Performs vector addition (A B i (Ay+ By)j Subtraction: Performs vector subtraction (Ax-B (Ay -Bij Equivalency: Returns true if two vectors are identical i e. have the same components) Not equal Returns true if two vectors are not identical Greater than: Retums true if Al is larger than BI (should call magnitude method K Less than Retums true if Alis smaller than BI (calls magnitude method) Dot Product: Retums the dot product of two vectors. Recall the dot product is computed as (As x B) +(Ay x B) Next, overload the following Unany operator: Negation: Returns a Vector2D object that is the inverse of the calling object. You may overload each operator as either a member, non-member, or non-member friend. Your solution should be done in 3 separate files Vector 2Dh The header file: Contains the class definition Vector2D.cpp The implementation file: ements/defines the methods and operator overloads Main cpp The application file: Contains main that tests your class Your main function should create at least three vectors objects (ets say A, B and C), test each of your class's operators and print statements for each showing that the operators work

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

=+approaches? Conflicting processes to address a challenge?

Answered: 1 week ago