Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <set>
- #include <string>
- #include <iostream>
- #include <numeric>
- using namespace std;
- // фигура
- class Shape {
- public:
- string GetColor() const {
- return color_;
- }
- void SetColor(string color) {
- color_ = color;
- }
- private:
- string color_ = "black";
- };
- // прямоугольник
- class Rectangle : public Shape {
- public:
- Rectangle(double a, double b) : a_(a), b_(b) {}
- double GetArea() {
- return a_ * b_;
- }
- private:
- double a_;
- double b_;
- };
- // треугольник
- class Triangle : public Shape {
- public:
- Triangle(double a, double b, double c) : a_(a), b_(b), c_(c) {}
- double GetArea() {
- double p = (a_ + b_ + c_) / 2;
- return sqrt(p * (p - a_) * (p - b_) * (p - c_));
- }
- private:
- double a_;
- double b_;
- double c_;
- };
- int main() {
- Rectangle rec(4, 5);
- Triangle tr(3, 4, 3);
- cout << rec.GetArea() << endl;
- cout << tr.GetArea() << endl;
- cout << rec.GetColor() << endl;
- rec.SetColor("white");
- cout << rec.GetColor() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement