consolidate all repos to one for archive
This commit is contained in:
11
semester_2/programiranje_2/primeri/Example09/Animal.h
Normal file
11
semester_2/programiranje_2/primeri/Example09/Animal.h
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef EXAMPLE09_ANIMAL_H
|
||||
#define EXAMPLE09_ANIMAL_H
|
||||
|
||||
class Animal { // abstract class
|
||||
public:
|
||||
virtual ~Animal() {}
|
||||
virtual void voice() const = 0; // abstract method
|
||||
};
|
||||
|
||||
#endif //EXAMPLE09_ANIMAL_H
|
13
semester_2/programiranje_2/primeri/Example09/Cat.h
Normal file
13
semester_2/programiranje_2/primeri/Example09/Cat.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef EXAMPLE09_CAT_H
|
||||
#define EXAMPLE09_CAT_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Cat : public Animal {
|
||||
public:
|
||||
void voice() const {
|
||||
std::cout << "meow" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE09_CAT_H
|
14
semester_2/programiranje_2/primeri/Example09/Cow.h
Normal file
14
semester_2/programiranje_2/primeri/Example09/Cow.h
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#ifndef EXAMPLE09_COW_H
|
||||
#define EXAMPLE09_COW_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Cow : public Animal {
|
||||
public:
|
||||
void voice() const {
|
||||
std::cout << "moo" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE09_COW_H
|
14
semester_2/programiranje_2/primeri/Example09/Dog.h
Normal file
14
semester_2/programiranje_2/primeri/Example09/Dog.h
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#ifndef EXAMPLE09_DOG_H
|
||||
#define EXAMPLE09_DOG_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
||||
void voice() const {
|
||||
std::cout << "bark" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE09_DOG_H
|
22
semester_2/programiranje_2/primeri/Example09/main.cpp
Normal file
22
semester_2/programiranje_2/primeri/Example09/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
#include "Animal.h"
|
||||
#include "Dog.h"
|
||||
#include "Cat.h"
|
||||
#include "Cow.h"
|
||||
|
||||
int main() {
|
||||
Animal* zoo[4];
|
||||
|
||||
//zoo[0] = new Animal;
|
||||
zoo[0] = new Dog;
|
||||
zoo[1] = new Cat;
|
||||
zoo[2] = new Dog;
|
||||
zoo[3] = new Cow;
|
||||
for (int i=0; i < 4; i++)
|
||||
zoo[i]->voice();
|
||||
|
||||
for (int i=0; i<4; i++)
|
||||
delete zoo[i];
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user