Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- class Figura {
- public:
- Figura *next;
- virtual void pole() {};
- virtual int pole2() { return 0; };
- virtual void obwod() {};
- };
- class Kwadrat :public Figura
- {
- public:
- int a;
- Kwadrat()
- {
- a = rand() % 10;
- }
- void pole()
- {
- cout << "Pole kwadratu: " << a*a << endl;
- }
- void obwod()
- {
- cout << "Obwod kwadratu: " <<4*a <<endl;
- }
- int pole2()
- {
- return a*a;
- }
- };
- class Kolo :public Figura
- {
- public:
- int r;
- Kolo()
- {
- r = rand() % 10;
- }
- void pole()
- {
- cout << "Pole kola: " << 3.14*r*r << endl;
- }
- void obwod()
- {
- cout << "Obwod kola: " << 2 * 3.14*r << endl;
- }
- int pole2()
- {
- return 3.14*r*r;
- }
- };
- class Prostokat :public Figura
- {
- public:
- int a, b;
- Prostokat()
- {
- a = rand() % 10;
- b = rand() % 10;
- }
- void pole()
- {
- cout << "Pole prostokata: " <<a*b<< endl;
- }
- void obwod()
- {
- cout << "Obwod prostokata: " << (2 * a) + (2 * b) << endl;
- }
- int pole2()
- {
- return a*b;
- }
- };
- int main()
- {
- int suma=0;
- Figura *tmp, *H = NULL;
- srand(time(NULL));
- for (int i = 0; i < 20; i++)
- {
- switch (rand() % 3)
- {
- case 0:
- tmp = new Kwadrat();
- tmp->pole();
- tmp->obwod();
- break;
- case 1:
- tmp = new Kolo();
- tmp->pole();
- tmp->obwod();
- break;
- case 2:
- tmp = new Prostokat();
- tmp->pole();
- tmp->obwod();
- break;
- }
- cout << endl;
- tmp->next = H;
- H = tmp;
- }
- Figura *M = H;
- Figura *MM = H;
- while (M)
- {
- suma += (M->pole2());
- M = M->next;
- }
- cout << "SREDNIA: " << suma/20<< endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement