Advertisement
tei123

orkiestra

May 22nd, 2018
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class instrum
  5. {
  6. public:
  7. virtual void dzwiek()
  8. {
  9. cout <<"cisza";
  10. }
  11. virtual ~instrum()//wirtualny destruktor
  12. {
  13. cout<<"destruktor instrumentu";
  14. }
  15. };
  16. class skrzypce : public instrum
  17. {
  18. string nazwa;
  19. int *tabl_numerow;
  20. public :
  21. //konstruktor
  22. skrzypce (string firma, int rok_produkcji, int nr_seryjny)
  23. :nazwa(firma)
  24. {
  25. tabl_numerow = new int[2];
  26. tabl_numerow[0] = rok_produkcji;
  27. tabl_numerow[1] = nr_seryjny;
  28. }
  29. ~ skrzypce()
  30. {
  31. cout <<"destruktor skrzypiec +";
  32. delete [] tabl_numerow;
  33. }
  34. void dzwiek()
  35. {
  36. cout <<"Tirli-tirli ("<<nazwa<<")\n";
  37. }
  38. };
  39. class gwizdek : public instrum
  40. {
  41. public:
  42. void dzwiek ()
  43. {
  44. cout << "Gwizd-gwizd\n";
  45. }
  46. };
  47. class gitara:public instrum
  48. {
  49. string nazwa;
  50. int *tabl_numerow;
  51. public:
  52. //konstruktor
  53. gitara (string firma, int rok_produkcji, int nr_seryjny)
  54. :nazwa(firma)
  55. {
  56. tabl_numerow = new int[2];
  57. tabl_numerow[0] = rok_produkcji;
  58. tabl_numerow[1] = nr_seryjny;
  59. }
  60. ~ gitara()
  61. {
  62. cout <<"destruktor gitary +";
  63. delete [] tabl_numerow;
  64. }
  65. void dzwiek()
  66. {
  67. cout <<"brzdek-brzdek ("<<nazwa<<")\n";
  68. }
  69. };
  70. int main ()
  71. {
  72. cout <<"definiowanie w pamieci obiektow ";
  73. instrum *pierwszy = new skrzypce("Stradivarius",1736,630);
  74. instrum *drugi =new gitara ("Ramirez", 1997,14822);
  75. instrum *trzeci = new gwizdek;
  76.  
  77. pierwszy ->dzwiek();
  78. drugi ->dzwiek();
  79. trzeci ->dzwiek();
  80. cout <<"usuwanie instrumentow\n";
  81.  
  82. delete pierwszy;
  83. cout << string(50, '*')<< endl;
  84. delete drugi;
  85. cout << string(50, '*')<< endl;
  86. delete trzeci;
  87. return 0;
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement