Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART ONE: Create a new C++ project, named hw3. 1. Design a class Shape that stores x and y coordinates of a shape. Write the

PART ONE: Create a new C++ project, named hw3.

1. Design a class Shape that stores x and y coordinates of a shape. Write the class declaration in the header file (.h) and the class definition in the implementation file (.cpp). Your class must have the following public methods:

1a. Constructor with two arguments for x and y

1b. Draw prints statement, such as drawing a shape with coordinates (2.3)

1c. Print prints statement, such as this is a shape with coordinates (2.3)

2. Create a main.cpp source file with int main() function.

3. Include your name in your cpp function as a comment, e.g., // John Doe

4. Write test code to create three objects of type Shape. Call both draw and print method on each object.

5. Create pointers for each of your three objects.

6. Call both draw and print function on each object using these pointers with the -> operator.

Your program should produce an output similar to the following:

calling the draw() function: drawing a shape with coordinates (10, 24) drawing a shape with coordinates (4, 2) drawing a shape with coordinates (-5, 8)

calling the print() function: printing a shape with coordinates (10, 24) printing a shape with coordinates (4, 2) printing a shape with coordinates (-5, 8)

USING POINTERS: calling the draw() function: drawing a shape with coordinates (10, 24) drawing a shape with coordinates (4, 2) drawing a shape with coordinates (-5, 8)

calling the print() function: printing a shape with coordinates (10, 24) printing a shape with coordinates (4, 2) printing a shape with coordinates (-5, 8)

PART TWO: This part assumes you have solved Part 1.

1. Derive a class Circle from the Shape class.

Your Circle class should contain an additional member variable representing radius.

Define a constructor that takes x, y and radius as its arguments.

In your Circle class, override the following two methods inherited from Shape:

1a. Draw prints statement, such as drawing a circle with coordinates (2,3) and radius 5

1b. Print prints statement, such as printing a circle with coordinates (2,3) and radius 5

2. DeriveaclassRectanglefromtheShapeclass.

Your Rectangle class should contain two additional member variables

representing width and length of the rectangle.

Define a constructor that takes x, y, w, and l as its arguments.

In your Rectangle class, override the following two methods inherited from

Shape: 2a. Draw prints statement, such as drawing rectangle, (12,5), w = 8, l = 5

2b. Print prints statement, such as printing rectangle, (12,5), w = 8, l = 5

3. Define a class Picture that has three pointer variables for storing shapes. Each variable is a pointer that points to an object of type Shape.

4. Your picture class should have a member variable to store its name, and a four- argument constructor that initializes this variable and assigns three pointer variables.

4a. Define two methods for your picture class draw and print, that call each of the three shapes draw and print methods, respectively. For example, pictures draw method should make three method calls - one for each of the three shapes.

4b. In the Shape class, make draw function virtual (not pure virtual though), while print should remain a regular (non-virtual) function.

5. Add the following to the main() method of your main.cpp file. Create three objects of type Shape (a shape, a circle, and a rectangle), and an object of type Picture that represents these three shapes. Call its draw and print methods.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions