Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class figura{
  6. protected:
  7. string *kolor;
  8.  
  9. public:
  10. figura():kolor(new string("brak")){}
  11. figura(const string &q1):kolor(new string(q1)){}
  12.  
  13. virtual double pole()const=0;
  14.  
  15. virtual ~figura(){
  16. delete kolor;}
  17.  
  18. };
  19.  
  20. class kolo:public figura{
  21. protected:
  22. double r;
  23. public:
  24. kolo():r(0){}
  25. kolo(const string &q1, const double &q2):figura(q1),r(q2){}
  26. double pole()const{
  27. return 3.14*r*r;
  28. }
  29.  
  30. virtual ~kolo(){}
  31. };
  32.  
  33. class prost:public figura{
  34. protected:
  35. double a,b;
  36. public:
  37.  
  38. prost():a(0),b(0){}
  39. prost(const string &q1, const double &q2, const double &q3):figura(q1),a(q2),b(q3){}
  40. double pole()const{
  41. return a*b;
  42. }
  43.  
  44. virtual ~prost(){}
  45. };
  46.  
  47. class prostop:public prost{
  48. protected:
  49. double h;
  50. public:
  51.  
  52.  
  53. prostop():h(0){}
  54. prostop(const string &q1,const double &q2, const double &q3, const double &q4):prost(q1,q2,q3),h(q4){}
  55.  
  56. double pole()const{
  57. return 2*(a*b)+2*(a*h)+2*(b*h);
  58. }
  59.  
  60. virtual ~prostop(){}
  61. };
  62.  
  63. int main()
  64. {
  65. const kolo test1("czarny",100);
  66. const prostop test2("szary",2,2,2);
  67. typedef figura* wsk;
  68. figura* tab[5];
  69.  
  70. tab[0]=new kolo("czerwony",1);
  71. tab[1]=new kolo;
  72. tab[2]=new prost("niebieski",1,1);
  73. tab[3]=new prostop("zielony",1,1,1);
  74. tab[4]=new prostop;
  75.  
  76. for (int i=0;i<5;++i)
  77. cout<<tab[i]->pole()<<endl;
  78. cout<<"******* 3 *******" <<endl;
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement