Question: Problem 2. (45 points) In this exercise, you will implement a base class called Shape, and two derived classes Rect- angle and Circle in C++


Problem 2. (45 points) In this exercise, you will implement a base class called Shape, and two derived classes Rect- angle and Circle in C++ programming language. You should put your class definitions and function prototypes in a header (.h) file and definitions in a source (.cpp) file separately. If your functions are one-liners, you may choose to include them in the header file. (a) (15 Points] Shape class: Create a base class representing a shape. [-] two private ints (to designate the location of the object), and name them x and y. [+] implement a single constructor such that if called with two arguments x and y, creates a Shape located at (,y). Support the following four operations using the given function signatures: [+] Get the x coordinate, [+] Get the y coordinate [+] Set the x coordinate, [+] Set the y coordinate [+] Implement a method called MoveShape with two arguments Inew and Ynew such that location of the shape is updated with the inputs arguments. [+] implement a method to displace a Shape with two arguments rA and ya such that location of the shape is updated with x +XA and y+ya, respectively. [+] two virtual functions to draw Shape (see the sample runs) and to compute and return area of the shape. (b) (15 Points] Ellipse class: Create a derived class representing a ellipse. Note that the equation of a standard ellipse centered at the origin with width 2a and height 2b is: += 1. [-] two private ints (to designate the width and height of the object). [+] implement a single constructor that, if called with 0 arguments, initializes a unit Ellipse at the origin - (0,0) and halfwidth = halfheight = 1, but if called with four arguments z, y, a, b, creates a Ellipse located at 1, y) with (halfwidth, halfheight) = (a,b). (Hint: You will need to use default arguments.) Support the following operations using the given function signatures: [+] Get width, [+] Get height, [+] Set width, [+] Set height [+] implement draw Shape function for Ellipse. [+] implement area function for Ellipse that returns the area of the object. i.e., *a*b. (c) (15 Points] Circle class: Create a derived class representing a circle. [-] one private ints (to designate the radius of the circle). [+] implement a single constructor that, if called with O arguments, initializes a unit Circle at the origin - (0,0) and radius = 1, but if called with three arguments 2, y, r, creates a Circle located at (x, y) with (radius=r). Support the following operations using the given function signatures: [+] Get radius, [+] Set radius [+] implement draw Shape function for Circle [+] implement area function for Circle that return the area of the object, i.e., r2. Using the provided q2r-TestShape.cpp code to test your classes defined above with the defined properties. You don't need to modify but you have to upload q2r-TestShape.cpp. However, your program will be tested with other sets of inputs. See the sample run below. Zafers-MacBook-Pro:q2r-solution zafer / shapeTest Drawing an Ellipse at:(5,6), width 5, height 6 Drawing an Ellipse at:(105, 106), width 5, height 6 shape_area: 94.245 Drawing a Circle at: (15,25), radius 8 Drawing a Circle at:(115, 125), radius 8 shape_area: 201.856 Drawing an Ellipse at:(1,1), width 1, height 1 Drawing an Ellipse at:(101,101), width 1, height 1 shape_area: 3.1415 Drawing a Circle at:(0,0), radius 1 Drawing a Circle at:(100,100), radius 1 shape_area: 3.1415 q2r_TestShape.cpp 1 #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
