Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Define an abstract base class called BasicShape. The BasicShape class should have the following members: (Reference: Fig 12.9 and 12.10) a) Protected Member Variable:

image text in transcribed
1. Define an abstract base class called BasicShape. The BasicShape class should have the following members: (Reference: Fig 12.9 and 12.10) a) Protected Member Variable: area (a double used to hold the shape's area). b) Private Member Variable: name (a string to indicate the shape's type) c) Constructor and Public Member Functions: . BasicShape(double a, string n): A constructor that sets value of member area. with a and member name with n. calcArea(): This public function should be a pure virtual function. print(): A public virtual function that only prints the value of data member area . getName():A public function that returns the value of data member name 2. Define a class named Circle. It should be derived from the BasicShape class. It should have the following members: (Reference: Fig 12.11 and 12.12) a) Private Member Variable: radius (a double used to hold the circle's radius) b) Constructor and Public Member Functions: . Circle(double- a, string n, double r): constructor that should call the base class constructor to initialize the member area with a and name with n. The constructor will also set the value of member radius with r calcArea(). Overridden function that calculates the area of the circle (area = 3.14159 * radius * radius) and stores the result in the inherited member area. print(): Overridden function that will print the radius, inherited member area and inherited member name. This function should use the base class's print function to print the area. 3. After you have created these classes, create a test program (Reference: Fig 12.17) Write a function named poly whose only parameter is a BasicShape pointer. Function poly should use the BasicShape pointer to invoke calcArea function and print function. In main(): define a Circle object with initial area 0, name Round and radius 10. From main(), call the function poly such that it will polymorphically (i.e. using a pointer of the base class) invoke calcArea function and print function of the Circle object

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions