Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The answer for this question can be submitted in C++ 1)Define a class point and use this class in your main function. You are expected

The answer for this question can be submitted in C++

1)Define a class point and use this class in your main function. You are expected to meet the following criteria: 1) The class has two private members, double x and double y, to represent the points x and y coordinates (4 points).

2) The class has two constant public member functions, get_x() and get_y(), that allow us to retrieve the current x and y of a point (5 point).

3) The class has a modification public member function, shift(double x_amount, double y_amount), that allow us to shift a point by given amounts along the x and y axes (5 point).

4) The class has a modification public member function, rotate90(), that allows us to rotate a point by 90 in a counterclockwise direction around the origin axes (6 point). (Hint: For a 90-degree counterclockwise rotation, the new x is the original -y, and the new y is the original x).

5) The class has a constructor function point(double initial_x, double initial_y) that allow us to initialize the coordinate of a point (6 point); The constructor also has two default arguments: initial_x = 0, initial_y = 0 (2 point).

6) In your main function, i) create an object of your point class (1 points); ii) shift the coordinate of your point by (a, b) via function shift (1 points); iii) rotate the point once via function rotate90 (1 points); and iv) print out (e.g., using cout) the points current coordinate in format: The current coordinate is (x, y). (2 points)

7) Define an overloading binary arithmetic operator - for your class: if we have two objects p1 and p2 with coordinates (x1, y2) and (x2, y2), respectively, then p1 p2 will return a point object with coordinate (x1- x2, y1- y2) (5 point). (Hint: you can refer the example of overloading operator + in page 76-77 in our textbook).

8) Define a function rotations_needed of which the argument (input) is a point object, say p, and the return value (output) is the number of 90-degree counterclockwise rotations needed to move p into the upper-left quadrant (when x <0, y > 0). After calling this function, the coordinate of your object p wont be changed (5 point).

9) Define a function rotate_to_upper_left that can rotate a point object to the upper-left quadrant. Note that the coordinate of original p will be changed after calling this function (5 point).

10) Please dont forget to write a postcondition for each of your function. If a function has any argument, you also need to have a precondition before defining this function (2 point).

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

Students also viewed these Databases questions