init commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
class Figure {
|
||||
public:
|
||||
virtual double get_square() const = 0;
|
||||
virtual ~Figure() {};
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
// class Figure {
|
||||
// public:
|
||||
// virtual double get_square() const = 0;
|
||||
// virtual ~Figure() {};
|
||||
// };
|
||||
|
||||
class Rectangle : Figure {
|
||||
double a;
|
||||
double b;
|
||||
public:
|
||||
Rectangle(double a = 0, double b = 0) : a(a), b(b) {}
|
||||
double get_square() const {
|
||||
return a * b;
|
||||
}
|
||||
static Rectangle* make(std::string s) {
|
||||
std::istringstream ss(s);
|
||||
double a, b;
|
||||
ss >> a >> b;
|
||||
|
||||
return new Rectangle(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
class Square : Figure {
|
||||
double a;
|
||||
public:
|
||||
Square(double a = 0) : a(a) {}
|
||||
double get_square() const {
|
||||
return a * a;
|
||||
}
|
||||
static Square* make(std::string s) {
|
||||
std::istringstream ss(s);
|
||||
double a;
|
||||
ss >> a;
|
||||
|
||||
return new Square(a);
|
||||
}
|
||||
};
|
||||
|
||||
class Circle : Figure {
|
||||
double r;
|
||||
public:
|
||||
Circle(double r = 0) : r(r) {}
|
||||
double get_square() const {
|
||||
return M_PI * r * r;
|
||||
}
|
||||
static Circle* make(std::string s) {
|
||||
std::istringstream ss(s);
|
||||
double r;
|
||||
ss >> r;
|
||||
|
||||
return new Circle(r);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
class Figure {
|
||||
public:
|
||||
virtual bool equals(const Figure*) const = 0;
|
||||
virtual ~Figure() {}
|
||||
};
|
||||
|
||||
class Rectangle : Figure {
|
||||
int a;
|
||||
int b;
|
||||
public:
|
||||
Rectangle(int a = 0, int b = 0) : a(a), b(b) {}
|
||||
bool equals(const Figure* fig) const {
|
||||
const Rectangle* rect = dynamic_cast<const Rectangle*>(fig);
|
||||
if (rect) {
|
||||
return a == rect->a && b == rect->b;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Triangle : Figure {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
public:
|
||||
Triangle(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
|
||||
bool equals(const Figure* fig) const {
|
||||
const Triangle* tri = dynamic_cast<const Triangle*>(fig);
|
||||
if (tri) {
|
||||
return a == tri->a && b == tri->b && c == tri->c;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user