I need c++ programming with output Pure Abstract Base Class Project. Define a cl
ID: 3854026 • Letter: I
Question
I need c++ programming with output
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function.
Define a class called Circle. It should be a derived class of the BasicShape class. This class will have 3 private data members. It will have 2 long integer data members called centerX and centerY. The last data member is a double called radius. It will have a constructor that accepts values for centerX, centerY and radius. This constructor should call the overridden calcArea function of this class. This class defines its version of the calcArea function which determines the area of the circle using the formula area = 3.14159 * radius * radius. The class will also provide two functions called getCenterX and getCenterY which return the correct values.
Define a class called Rectangle. It should be a derived class of the BasicShape class. This class will have 2 private data members called width and length. Both data members should be long integers. Its constructor will have parameters for both the width and length. It will also override the calcArea function. For this class the calcArea function will use the formula area = length * width. It will provide member function called getWidth and getLength which should return the correct values.
In main create instances of the Circle and Rectangle classes. It should then display the area of the two shapes using a function defined as
void DisplayArea(BasicShape* shape)
** I found other programs too for the same question, but there is no .cpp file for BasicShape class. Why is that?**
Explanation / Answer
Main.cpp file
#include "Pure.h"
#include <iostream>
using namespace std;
int main() {
Circle pizza(2,2,10);
Rectangle box(10,5);
cout << "The Circle's information: " << endl;
cout << "Center x = " << pizza.getCenterX() << endl;
cout << "Center y = " << pizza.getCenterY() << endl;
cout << "Area = " << pizza.getArea() << endl << endl << endl;
cout << "The Rectangle's information: " << endl;
cout << "Length = " << box.getLength() << endl;
cout << "Width = " << box.getWidth() << endl;
cout << "Area = " << box.getArea() << endl;
}
.H file
#ifndef PURE_H
#define PURE_H
class BasicShape {
protected:
double area;
public:
double getArea() const;
virtual void calcArea() ; //used to make BasicShape a pure abstract base class
};
class Circle : public BasicShape {
private:
long centerX;
long centerY;
double radius;
public:
Circle(long, long, double);
long getCenterX() const;
long getCenterY() const;
virtual void calcArea() ;
};
class Rectangle : public BasicShape {
private:
long width;
long length;
public:
Rectangle(long,long);
long getWidth() const;
long getLength() const;
virtual void calcArea() ;
};
#endif
.cpp file
#include "Pure.h"
double BasicShape :: getArea() const {
return area;
}
Circle::Circle(long x, long y,double r) {
centerX = x;
centerY = y;
radius = r;
calcArea();
}
long Circle::getCenterX() const {
return centerX;
}
long Circle::getCenterY() const {
return centerY;
}
void Circle::calcArea() {
area = 3.14159 * radius * radius;
}
Rectangle::Rectangle(long L, long W) {
length = L;
width = W;
calcArea();
}
long Rectangle::getWidth() const {
return width;
}
long Rectangle::getLength() const {
return length;
}
void Rectangle::calcArea() {
area = length * width;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.