Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define an abstract base class called BasicShape. The BasicShape class should hav

ID: 3832243 • Letter: D

Question

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) Constructor and Public Member Functions: BasicShape (double a, siring n): A c) 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

Explanation / Answer

#include <iostream>
using namespace std;
class BasicShape
{
//a) Protected Member Variable: area (a double used to hold the shape’s area).
protected:
double area;
//b) Private Member Variable: name (a string to indicate the shape’s type)
private:
string name;
public:
//BasicShape(double a, string n): A constructor that sets value of member area with a and member name with n.
BasicShape(double a, string n)
{
area = a;
name = n;
}
//calcArea(): This public function should be a pure virtual function.
virtual void calcArea() = 0;
//print(): A public virtual function that only prints the value of data member area.
virtual void print()
{
cout<<"Area: "<<area<<endl;
}
//getName():A public function that returns the value of data member name.
string getName()
{
return name;
}
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote