mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-10-28 11:10:38 +01:00
prawie zrobione zadania
This commit is contained in:
40
uczelnia/2_semestr/programowanie/laby/lab10/zad1.cpp
Normal file
40
uczelnia/2_semestr/programowanie/laby/lab10/zad1.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
|
||||
class Zwierze {
|
||||
public:
|
||||
virtual void odglos() { std::cout << "..." << std::endl; }
|
||||
virtual ~Zwierze() = default;
|
||||
};
|
||||
|
||||
class Pies : public Zwierze {
|
||||
public:
|
||||
void odglos() override { std::cout << "Hau hau" << std::endl; }
|
||||
};
|
||||
|
||||
class Kot : public Zwierze {
|
||||
public:
|
||||
void odglos() override { std::cout << "Miau miau" << std::endl; }
|
||||
};
|
||||
|
||||
class Krowa : public Zwierze {
|
||||
public:
|
||||
void odglos() override { std::cout << "Muu muu" << std::endl; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
const int SIZE = 3;
|
||||
Zwierze *zwierzeta[SIZE];
|
||||
zwierzeta[0] = new Pies();
|
||||
zwierzeta[1] = new Kot();
|
||||
zwierzeta[2] = new Krowa();
|
||||
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
zwierzeta[i]->odglos();
|
||||
}
|
||||
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
delete zwierzeta[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user