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:
- Shape(string color) : color_(color) {}
- void SetColor(string color) {
- color_ = color;
- }
- string GetColor() const {
- return color_;
- }
- private:
- string color_;
- };
- class Rectangle : public Shape {
- public:
- Rectangle(string color, double a, double b) : Shape(color), a_(a), b_(b) {}
- double GetArea() const {
- return a_ * b_;
- }
- private:
- double a_;
- double b_;
- };
- class Triangle : public Shape {
- public:
- Triangle(string color, double a, double b, double c) : Shape(color), a_(a), b_(b), c_(c) {}
- double GetArea() const {
- 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("black", 4, 5);
- Triangle tr("white", 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