Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- class Zwierze
- {
- private:
- float Waga;
- char Plec[10];
- int Wiek;
- protected:
- Zwierze(float waga, char plec[10], int wiek);
- void Wyswietl();
- };
- Zwierze::Zwierze(float waga, char plec[10], int wiek):
- Waga(waga), Wiek(wiek)
- {
- strcpy(Plec, plec);
- }
- void Zwierze::Wyswietl()
- {
- printf("Waga: %.2f\nPlec: %s\nWiek: %d", Waga, Plec, Wiek);
- }
- class Ssak : private Zwierze
- {
- private:
- float Temperatura;
- public:
- Ssak(float waga, char plec[10],int wiek, float temperatura);
- void Wyswietl();
- };
- Ssak::Ssak(float waga, char plec[10],int wiek, float temperatura):
- Zwierze(waga, plec, wiek),
- Temperatura(temperatura)
- {
- }
- void Ssak::Wyswietl()
- {
- Zwierze::Wyswietl();
- printf("\nTemperatura: %.2f", Temperatura);
- }
- class Gepard : private Ssak
- {
- private:
- float Bieg;
- public:
- Gepard(float waga, char plec[10],int wiek, float temperatura, int bieg);
- void Wyswietl();
- };
- Gepard::Gepard(float waga, char plec[10],int wiek, float temperatura, int bieg):
- Ssak(waga, plec, wiek,temperatura),
- Bieg(bieg)
- {
- }
- void Gepard::Wyswietl()
- {
- Ssak::Wyswietl();
- printf("\nBieganie(max V): %.2f", Bieg);
- }
- class Delfin : private Gepard
- {
- private:
- float Rekord;
- public:
- Delfin(float waga, char plec[10],int wiek, float temperatura, float bieg, float rekord);
- void Wyswietl();
- };
- Delfin::Delfin(float waga, char plec[10],int wiek, float temperatura, float bieg, float rekord):
- Gepard(waga, plec, wiek,temperatura, bieg),
- Rekord(rekord)
- {
- }
- void Delfin::Wyswietl()
- {
- Gepard::Wyswietl();
- printf("\nPlywanie(max V): %.2f", Rekord);
- }
- int main()
- {
- printf("***** Program przedstawiajacy dzialanie dziedziczenia *****\n\n");
- Ssak ssak(2.7, "Samiec", 47, 5.4);
- ssak.Wyswietl();
- printf("\n\n");
- Gepard gepard(3.6, "Samica", 200, 36.9, 55.4);
- gepard.Wyswietl();
- printf("\n\n");
- Delfin delfin(17.5, "Samica", 167, 22.7, 0, 22.4);
- delfin.Wyswietl();
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment