Código C++:
Ver original#include <iostream>
#include <stdlib.h>
using namespace std;
/**
* Clase Figura
**/
class Figura{
public:
virtual double area() = 0;
virtual double circUnferencia() = 0;
};
/**
* Clase Circulo
**/
class Circulo : public Figura{
protected:
double r;
public:
Circulo(){
r = 1.0;
};
Circulo(double r){
this->r = r;
};
double area(){
return 3.1416*r*r;
};
double circUnferencia(){
return 2*3.1416*r;
};
double getR(){
return r;
};
};
/**
* Clase Rectangle
**/
class Rectangle : public Figura {
protected:
double l, a;
public:
Rectangle() {
l = 0.0;
a = 0.0;
};
Rectangle(double l, double a){
this->l = l;
this->a = a;
};
double area(){
return l*a;
};
double circUnferencia(){
return 2*(l+a);
};
double getL(){
return l;
};
double getA(){
return a;
};
};
int main()
{
double total_area=0;
int n=3;
Figura **figuras;
figuras = new Figura*[n];
figuras[0]=new Circulo(2);
figuras[1]=new Rectangle(1,3);
figuras[2]=new Rectangle(4,2);
for(int i = 0; i < 3; i++){
cout << endl << figuras[i]->area();
total_area += figuras[i]->area();
}
cout<<"\n\n "<<total_area;
return 0;
}