pieniakoskar

Zwierzaki

Mar 19th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. class Zwierze
  6. {
  7. private:
  8. float Waga;
  9. char Plec[10];
  10. int Wiek;
  11.  
  12. protected:
  13. Zwierze(float waga, char plec[10], int wiek);
  14. void Wyswietl();
  15. };
  16.  
  17. Zwierze::Zwierze(float waga, char plec[10], int wiek):
  18. Waga(waga), Wiek(wiek)
  19. {
  20. strcpy(Plec, plec);
  21. }
  22.  
  23. void Zwierze::Wyswietl()
  24. {
  25. printf("Waga: %.2f\nPlec: %s\nWiek: %d", Waga, Plec, Wiek);
  26. }
  27.  
  28. class Ssak : private Zwierze
  29. {
  30. private:
  31. float Temperatura;
  32. public:
  33. Ssak(float waga, char plec[10],int wiek, float temperatura);
  34. void Wyswietl();
  35. };
  36.  
  37. Ssak::Ssak(float waga, char plec[10],int wiek, float temperatura):
  38. Zwierze(waga, plec, wiek),
  39. Temperatura(temperatura)
  40. {
  41. }
  42.  
  43. void Ssak::Wyswietl()
  44. {
  45. Zwierze::Wyswietl();
  46. printf("\nTemperatura: %.2f", Temperatura);
  47. }
  48.  
  49. class Gepard : private Ssak
  50. {
  51. private:
  52. float Bieg;
  53. public:
  54. Gepard(float waga, char plec[10],int wiek, float temperatura, int bieg);
  55. void Wyswietl();
  56. };
  57.  
  58. Gepard::Gepard(float waga, char plec[10],int wiek, float temperatura, int bieg):
  59. Ssak(waga, plec, wiek,temperatura),
  60. Bieg(bieg)
  61. {
  62. }
  63.  
  64. void Gepard::Wyswietl()
  65. {
  66. Ssak::Wyswietl();
  67. printf("\nBieganie(max V): %.2f", Bieg);
  68. }
  69.  
  70. class Delfin : private Gepard
  71. {
  72. private:
  73. float Rekord;
  74. public:
  75. Delfin(float waga, char plec[10],int wiek, float temperatura, float bieg, float rekord);
  76. void Wyswietl();
  77. };
  78.  
  79. Delfin::Delfin(float waga, char plec[10],int wiek, float temperatura, float bieg, float rekord):
  80. Gepard(waga, plec, wiek,temperatura, bieg),
  81. Rekord(rekord)
  82. {
  83. }
  84.  
  85. void Delfin::Wyswietl()
  86. {
  87. Gepard::Wyswietl();
  88. printf("\nPlywanie(max V): %.2f", Rekord);
  89. }
  90. int main()
  91. {
  92. printf("***** Program przedstawiajacy dzialanie dziedziczenia *****\n\n");
  93.  
  94. Ssak ssak(2.7, "Samiec", 47, 5.4);
  95. ssak.Wyswietl();
  96. printf("\n\n");
  97. Gepard gepard(3.6, "Samica", 200, 36.9, 55.4);
  98. gepard.Wyswietl();
  99. printf("\n\n");
  100. Delfin delfin(17.5, "Samica", 167, 22.7, 0, 22.4);
  101. delfin.Wyswietl();
  102.  
  103.  
  104.  
  105. getch();
  106. return 0;
  107. }
Add Comment
Please, Sign In to add comment