Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Solve using C++ in Visual Studio text editor please with comments of explanation Part 1 Create a new project named lab1_1 and create a class
Solve using C++ in Visual Studio text editor please with comments of explanation
Part 1 Create a new project named lab1_1 and create a class named Point to represent in a point in 2 dimensional space. The Point class will have two private member variables named x and y. This class should contain two constructors: a default constructor, and an overloaded constructor, which takes two arguments, and uses these to set the coordinates of x and y. There will be setters and getters for x and y, as well as a method named move, which move x and y with the amount specified by the arguments. There will also be a print method, which prints out the coordinates as: (2, 3) for a point with coordinates (2,3). Make sure to test this with a driver file. Part 2 Write a definition of a class Rectangle using the Point class. A rectangle is specified by two corner points (bottom left and top right). The sides of the rectangle are parallel to the coordinate axes. The implementation of the class should be as follows: The private data members of the class include all 4 comer points of the rectangle. There are two constructors: one takes two points as arguments and creates a rectangle with the first point as the bottom left comer and the second as the top right comer, the other (default) constructor creates a rectangle with the corners (0,0), (1,0), (0,1), (1,1). Hint: use your setters from the class Point to set the values of the comer points. The print member function prints all 4 corners of the rectangle, using the member function print of the class Point. Test the class Rectangle in main(), demonstrate that all member functions work as specified. Part 3 Add two private member functions sidel, side2 to the class Rectangle to compute the lengths of the two sides. Using this function, write a public member function to compute the area of the rectangle. Sample Execution: Enter the x and y coordinates of your point: -1 -2 Here is your point: (-1, -2) Enter the x and y coordinates of your next point: 4 1 Here is your rectangle: (-1 ,-2) (-1, 1) (4, 1) (4, -2) The area of your rectangle is: 15 Another Sample Execution: Enter the x and y coordinates of your point: 11 Here is your point: (1, 1) Enter the x and y coordinates of your next point: 5 6 Here is your rectangle: (1,1) (1, 6) (5, 6) (5, 1) The area of your rectangle is: 20Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started