consolidate all repos to one for archive
This commit is contained in:
27
semester_2/programiranje_2/primeri/Example11/House.h
Normal file
27
semester_2/programiranje_2/primeri/Example11/House.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef EXAMPLE11_HOUSE_H
|
||||
#define EXAMPLE11_HOUSE_H
|
||||
|
||||
#include <iostream>
|
||||
#include "Room.h"
|
||||
|
||||
class House {
|
||||
private:
|
||||
std::string name;
|
||||
Room kitchen, livingRoom, bedroom; //composition
|
||||
public:
|
||||
House(std::string name) : name(name), kitchen("Kitchen1"), livingRoom("living room 1"),
|
||||
bedroom("TV bedroom") {
|
||||
std::cout << "House::constructor" << std::endl;
|
||||
}
|
||||
virtual ~House() {
|
||||
std::cout << "House::destructor" << std::endl;
|
||||
}
|
||||
virtual void print() const {
|
||||
std::cout << "House name: " << name << std::endl;
|
||||
kitchen.print();
|
||||
livingRoom.print();
|
||||
bedroom.print();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE11_HOUSE_H
|
21
semester_2/programiranje_2/primeri/Example11/Room.h
Normal file
21
semester_2/programiranje_2/primeri/Example11/Room.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef EXAMPLE11_ROOM_H
|
||||
#define EXAMPLE11_ROOM_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Room {
|
||||
private:
|
||||
std::string name;
|
||||
public:
|
||||
Room(std::string name) : name(name) {
|
||||
std::cout << "Room::constructor" << std::endl;
|
||||
}
|
||||
virtual ~Room() {
|
||||
std::cout << "Room::destructor" << std::endl;
|
||||
}
|
||||
virtual void print() const {
|
||||
std::cout << "Room " << name << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EXAMPLE11_ROOM_H
|
15
semester_2/programiranje_2/primeri/Example11/main.cpp
Normal file
15
semester_2/programiranje_2/primeri/Example11/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <iostream>
|
||||
#include "House.h"
|
||||
|
||||
int main() {
|
||||
std::cout << "Composition example" << std::endl;
|
||||
{
|
||||
std::cout << "----------- nested block begin -----------" << std::endl;
|
||||
House h1("My home");
|
||||
h1.print();
|
||||
std::cout << "----------- nested block end -----------" << std::endl;
|
||||
}
|
||||
std::cout<<"House and rooms don't exist anymore!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user