Question: In this exercise, you will implement a base class called Shape, and two derived classes Rectangle and Circle in C++ programming language. You should put

 In this exercise, you will implement a base class called Shape,

In this exercise, you will implement a base class called Shape, and two derived classes Rectangle 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 (x,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 xnew and ynew such that location of the shape is updated with the inputs arguments. [+] implement a method to displace a Shape with two arguments x and y such that location of the shape is updated with x+x and y+y, 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: a2x2+b2y2=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 x,y,a,b, creates a Ellipse located at (x,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., ab. (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 0 arguments, initializes a unit Circle at the origin (0,0) and radius =1, but if called with three arguments x,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 q2rTestShape.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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!