Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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 q2rTestShape.cpp. However, your program will be tested with other sets of inputs. See the sample run below. 4 [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.056 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: (,), radius 1 Drawing a Circle at: (100,100), radius 1 shape_area: 3.1415

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Question

Evaluate nCxp x (1p) nx for n=4, p=0.3, x=2.

Answered: 1 week ago