Advertisement
Guest User

asdsadasdasd

a guest
Jan 21st, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. #include <cstring>
  4.  
  5. class B{
  6. float a;
  7. public:
  8. B(float);
  9. virtual ~B();
  10. virtual void wypisz();
  11. float getA();
  12. };
  13.  
  14. B::B(float b){
  15. a = b;
  16. }
  17.  
  18. B::~B(){
  19. std::cout << "Destruktor klasy bazowej" << std::endl;
  20. }
  21.  
  22. void B::wypisz(){
  23. std::cout << "A = " << a << std::endl;
  24. }
  25.  
  26. float B::getA(){
  27. return a;
  28. }
  29.  
  30. class C:public B{
  31. char * m;
  32. public:
  33. C(char *, float);
  34. ~C();
  35. void wypisz();
  36. };
  37.  
  38. C::C(char * n, float x):B(x){
  39. int dlugosc_n = strlen(n);
  40. m = new char [dlugosc_n + 1];
  41. assert(m);
  42. std::strcpy(m,n);
  43. }
  44.  
  45. C::~C(){
  46. std::cout << "Destruktor klasy pochodnej" << std::endl;
  47. delete [] m;
  48. }
  49.  
  50. void C::wypisz(){
  51. std::cout << "m = " << m << " a = " << getA() << std::endl;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement