Advertisement
dadiw96

lab 4 klasy_obiekty

Apr 11th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class figura
  7. {
  8. public:
  9. float obwod;
  10. float pole;
  11.  
  12. figura(float pole=20,float obwod=20);
  13.  
  14.  
  15. };
  16. figura::figura(float pole,float obwod)
  17. {
  18. cout<<"Konstruktor figury"<<endl;
  19. this->pole=pole;
  20. this->obwod=obwod;//this wskazuje bezpośrednio na klase
  21. }
  22.  
  23. class prostokat:public figura
  24. {
  25. public:
  26. float a;
  27. float b;
  28. prostokat(float a=10,float b=20);
  29.  
  30. };
  31. prostokat::prostokat(float a,float b):figura(2*a+2*b,a*b)
  32. {
  33.  
  34. this->a=a;
  35. this->b=b;
  36. cout<<"Konstruktor prostokata"<<endl;
  37. }
  38.  
  39. //main()
  40. //{
  41. // figura kola(10,20);
  42. // prostokat kwadrat(5,5);
  43. // cout<<"Lacznie pola "<<kola.pole+kwadrat.pole<<endl;
  44. //}
  45.  
  46. main()
  47. {
  48. figura *f1=new figura(2,5);
  49. figura *f2=new figura(3,6);
  50. figura *f3=new prostokat(1.5,4.5);
  51. cout<<"Pola figur "<<f1->pole+(*f2).pole+f3->pole<<endl;//wyłskiwanie z wskaźnika odwołanie wskaźnikiem (->)
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement