Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Figure
- {
- string name;
- public:
- Figure(){;}
- Figure(string n_name){name = n_name;}
- virtual double field()
- {
- return 0;
- }
- virtual string type()
- {
- return "blank";
- }
- string show_name()
- {
- return name;
- }
- };
- class Square : public Figure
- {
- double a;
- public:
- Square(string n_name, double n_a):Figure(n_name){a = n_a;}
- virtual double field()
- {
- return a*a;
- }
- virtual string type()
- {
- return "kwadrat";
- }
- };
- class Triangle : public Figure
- {
- double a;
- double h;
- public:
- Triangle(string n_name, double n_a, double n_h):Figure(n_name){a = n_a; h = n_h;}
- virtual double field()
- {
- return 0.5*a*h;
- }
- virtual string type()
- {
- return "trojkat";
- }
- };
- class Container
- {
- int size;
- int counter;
- Figure figures[5];
- public:
- Container(int n_size){size = n_size; counter=0;}
- void show()
- {
- for(int i=0;i<counter;i++)
- {
- cout << figures[i].show_name() << " " << figures[i].type() << " " << figures[i].field() << endl;
- }
- }
- void add(Figure n_figure)
- {
- if(counter<size)
- {
- figures[counter] = n_figure;
- counter++;
- }
- else cout << "BRAK MIEJSCA!" << endl;
- }
- void del(double field)
- {
- for(int i=0;i<counter;i++)
- {
- if(figures[i].field()==field) figures[i] = Figure();
- }
- }
- };
- int main()
- {
- int a,h;
- string name;
- int n;
- //cin >> n;
- Container kontener(5);
- int m;
- //cin >> m;
- string typ;
- /*for(int i=0;i<m;i++)
- {
- cout << "PODAJ TYP: " << endl;
- cin >> typ;
- if(typ=="kwadrat")
- {
- cin >> name >> a;
- }
- else if(typ=="trojkat")
- {
- cin >> name >> a >> h;
- }
- }*/
- Square kwadrat("kwadracik",5);
- Triangle trojkat("trojkacik",4,3);
- cout << kwadrat.field() << " " << kwadrat.type() << " " << trojkat.field() << " " << trojkat.type() << endl;
- kontener.add(kwadrat);
- kontener.add(trojkat);
- kontener.show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement