Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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, 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] Rectangle class: Create a derived class representing a rectangle. [-] 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 Rectangle at the origin - (0,0) and width = height =1, but if called with four arguments x,y,w,h, creates a Rectangle located at (x,y) with (width, height) = (w,h). (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 Rectangle. [+] implement area function for Rectangle that returns the area of the object. (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. Using the provided q2 2_TestShape.cpp code to test your classes defined above with the defined properties. You don't need to modify or upload q2_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
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