Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <string>
- using namespace std;
- class Shape
- {
- protected:
- string name_;
- public:
- Shape(string name)
- {
- name_ = name;
- }
- ~Shape() {}
- string getName()
- {
- return name_;
- }
- virtual double area() = 0;
- };
- class ShapeContainer
- {
- public:
- vector <Shape*> Lista;
- ShapeContainer() {}
- void add(Shape* ptr)
- {
- Lista.push_back(ptr);
- }
- void displayAll() const
- {
- for (Shape* f : Lista)
- {
- cout<< f->getName() << " " << f->area() << endl;
- }
- }
- };
- class Rectangle : public Shape
- {
- protected:
- double width_;
- double height_;
- public:
- Rectangle(string name, double width, double height)
- : Shape(name)
- {
- width_ = width;
- height_ = height;
- }
- ~Rectangle() {}
- double area()
- {
- return width_ * height_;
- }
- double permiter()
- {
- return 2 * width_ + 2 * height_;
- }
- };
- class Square : public Rectangle
- {
- public:
- Square(string name, double width)
- :Rectangle(name, width, width)
- {}
- ~Square() {}
- double area()
- {
- return width_ * width_;
- }
- double permiter()
- {
- return 2 * width_;
- }
- };
- class Circle: public Shape
- {
- protected:
- double radius_;
- public:
- Circle(string name, double radius)
- :Shape(name)
- {
- radius_ = radius;
- }
- ~Circle() {}
- double area()
- {
- return 3.14 * radius_ * radius_;
- }
- double permiter()
- {
- return 2 * 3.14 * radius_;
- }
- double getRadius()
- {
- return radius_;
- }
- };
- class Elipse: public Shape
- {
- protected:
- double a_, b_;
- public:
- Elipse(string name, double a, double b)
- :Shape(name)
- {
- a_ = a;
- b_ = b;
- }
- double area()
- {
- return a_ * b_ * 3.14;
- }
- double permiter()
- {
- return 3.14 *(((3/2)*(a_+b_))- sqrt(a_*b_));
- }
- };
- int main()
- {
- int opcja;
- bool a = 1;
- while (a)
- {
- cout << endl;
- cout << "Wybierz opcje: " << endl;
- cout << "1. zadanie 1" << endl;
- cout << "2. zadanie 2" << endl;
- cout << "3. zadanie 3" << endl;
- cout << "4. zadanie 4" << endl;
- cout << "5. zakoncz " << endl;
- cin >> opcja;
- switch (opcja)
- {
- case 1:
- {
- ShapeContainer pojemnik;
- Square * kwadrat("kwadrat", 5);
- pojemnik.add(*kwadrat);
- break;
- }
- case 2:
- {
- break;
- }
- case 3:
- {
- break;
- }
- case 4:
- {
- break;
- }
- case 5:
- {
- a = 0;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement