Advertisement
Guest User

jjj

a guest
Apr 25th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5.  
  6. class Punkt
  7.  
  8. {
  9.  
  10. string nazwa;
  11. float x,y;
  12.  
  13. public:
  14. void wczytaj()
  15. {
  16. cout<<nazwa<<"("<<x<<","<<y<<")"<<endl;
  17. }
  18.  
  19. Punkt(string n="S", float xx=1, float yy=1)
  20. {
  21. nazwa=n;
  22. x=xx;
  23. y=yy;
  24. }
  25.  
  26.  
  27.  
  28.  
  29. };
  30.  
  31.  
  32. class Kolo :public Punkt //klasa Kolo dziedziczy publicznie z klasy punkt
  33. {
  34.  
  35.  
  36. string nazwa;
  37.  
  38. protected:
  39. float r;
  40.  
  41. public:
  42. void wczytaj()
  43. {
  44. cout<<"Kolo o nazwie: "<<nazwa<<endl;
  45. cout<<"Srodek kola: ";
  46. Punkt::wczytaj();
  47. cout<<endl<<"Promien kola: "<<r<<endl;
  48.  
  49. cout<<"Pole kola :"<<M_PI*r*r<<endl;
  50.  
  51. }
  52.  
  53. Kolo(string nk="kolko", string np="S", float a=1, float b=1, float pr=3)
  54. :Punkt(np,a,b)
  55. {
  56. nazwa = nk;
  57. r = pr;
  58.  
  59.  
  60.  
  61. }
  62.  
  63. };
  64.  
  65.  
  66. class Kula :public Kolo
  67. {
  68. string nazwa;
  69. public:
  70.  
  71. void wczytaj()
  72. {
  73. cout<<"Kula o nazwie: "<<nazwa<<endl;
  74. cout<<"Srodek kuli: ";
  75. Kolo::wczytaj();
  76. cout<<endl<<"Promien kuli: "<<r<<endl;
  77. cout<<"Objetosc kuli: "<<(4.0/3.0)*M_PI*r*r*r;
  78.  
  79. }
  80.  
  81. Kula(string nazwakola="kolko", string nazwapunkt="punkt", float aa=5, float bb=5, float prr=1, string nkula="kula", float rkula=1)
  82. :Kolo(nazwakola,nazwapunkt,aa,bb,prr)
  83. {
  84. nazwa=nkula;
  85. r=rkula;
  86.  
  87. }
  88.  
  89.  
  90.  
  91. };
  92.  
  93. int main()
  94. {
  95.  
  96. Kula k1;
  97. k1.wczytaj();
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement