diff options
10 files changed, 155 insertions, 155 deletions
| -rw-r--r-- | Sem. 13/Farm/Animals/Animal.h (renamed from Sem. 13/Farm/Animal.h) | 20 | ||||
| -rw-r--r-- | Sem. 13/Farm/Animals/Cat.cpp (renamed from Sem. 13/Farm/Cat.cpp) | 22 | ||||
| -rw-r--r-- | Sem. 13/Farm/Animals/Cat.h (renamed from Sem. 13/Farm/Cat.h) | 14 | ||||
| -rw-r--r-- | Sem. 13/Farm/Animals/Dog.cpp (renamed from Sem. 13/Farm/Dog.cpp) | 22 | ||||
| -rw-r--r-- | Sem. 13/Farm/Animals/Dog.h (renamed from Sem. 13/Farm/Dog.h) | 14 | ||||
| -rw-r--r-- | Sem. 13/Farm/Animals/Mouse.cpp (renamed from Sem. 13/Farm/Mouse.cpp) | 22 | ||||
| -rw-r--r-- | Sem. 13/Farm/Animals/Mouse.h (renamed from Sem. 13/Farm/Mouse.h) | 14 | ||||
| -rw-r--r-- | Sem. 13/Farm/Collection/Farm.cpp (renamed from Sem. 13/Farm/Farm.cpp) | 126 | ||||
| -rw-r--r-- | Sem. 13/Farm/Collection/Farm.h (renamed from Sem. 13/Farm/Farm.h) | 48 | ||||
| -rw-r--r-- | Sem. 13/Farm/source.cpp | 8 |
diff --git a/Sem. 13/Farm/Animal.h b/Sem. 13/Farm/Animals/Animal.h index 3911d49..9c55bce 100644 --- a/Sem. 13/Farm/Animal.h +++ b/Sem. 13/Farm/Animals/Animal.h @@ -1,11 +1,11 @@ -#pragma once
-#include <iostream>
-class Animal
-{
-public:
- virtual void sayHello() const = 0;
-
- virtual Animal* clone() const = 0;//създава копие на текущия обект.
-
- virtual ~Animal() {} //!!!
+#pragma once +#include <iostream> +class Animal +{ +public: + virtual void sayHello() const = 0; + + virtual Animal* clone() const = 0;//създава копие на текущия обект. + + virtual ~Animal() {} //!!! };
\ No newline at end of file diff --git a/Sem. 13/Farm/Cat.cpp b/Sem. 13/Farm/Animals/Cat.cpp index 4bb833a..8716d4b 100644 --- a/Sem. 13/Farm/Cat.cpp +++ b/Sem. 13/Farm/Animals/Cat.cpp @@ -1,12 +1,12 @@ -#include "Cat.h"
-
-void Cat::sayHello() const
-{
- std::cout << "Hello, I am a Cat!" << std::endl;
-}
-
-Animal* Cat::clone() const
-{
- Animal* newObj = new Cat(*this); //copy constr of Mouse
- return newObj;
+#include "Cat.h" + +void Cat::sayHello() const +{ + std::cout << "Hello, I am a Cat!" << std::endl; +} + +Animal* Cat::clone() const +{ + Animal* newObj = new Cat(*this); //copy constr of Mouse + return newObj; }
\ No newline at end of file diff --git a/Sem. 13/Farm/Cat.h b/Sem. 13/Farm/Animals/Cat.h index 1e1525d..8d60fd1 100644 --- a/Sem. 13/Farm/Cat.h +++ b/Sem. 13/Farm/Animals/Cat.h @@ -1,8 +1,8 @@ -#pragma once
-#include "Animal.h"
-class Cat : public Animal
-{
-public:
- void sayHello() const override;
- Animal* clone() const override;
+#pragma once +#include "Animal.h" +class Cat : public Animal +{ +public: + void sayHello() const override; + Animal* clone() const override; };
\ No newline at end of file diff --git a/Sem. 13/Farm/Dog.cpp b/Sem. 13/Farm/Animals/Dog.cpp index f44692c..879957f 100644 --- a/Sem. 13/Farm/Dog.cpp +++ b/Sem. 13/Farm/Animals/Dog.cpp @@ -1,12 +1,12 @@ -#include "Dog.h"
-
-void Dog::sayHello() const
-{
- std::cout << "Hello, I am a Dog!" << std::endl;
-}
-
-Animal* Dog::clone() const
-{
- Animal* newObj = new Dog(*this); //copy constr of Mouse
- return newObj;
+#include "Dog.h" + +void Dog::sayHello() const +{ + std::cout << "Hello, I am a Dog!" << std::endl; +} + +Animal* Dog::clone() const +{ + Animal* newObj = new Dog(*this); //copy constr of Mouse + return newObj; }
\ No newline at end of file diff --git a/Sem. 13/Farm/Dog.h b/Sem. 13/Farm/Animals/Dog.h index 26fc187..2c69e03 100644 --- a/Sem. 13/Farm/Dog.h +++ b/Sem. 13/Farm/Animals/Dog.h @@ -1,8 +1,8 @@ -#pragma once
-#include "Animal.h"
-class Dog : public Animal
-{
-public:
- void sayHello() const override;
- Animal* clone() const override;
+#pragma once +#include "Animal.h" +class Dog : public Animal +{ +public: + void sayHello() const override; + Animal* clone() const override; };
\ No newline at end of file diff --git a/Sem. 13/Farm/Mouse.cpp b/Sem. 13/Farm/Animals/Mouse.cpp index a6dc30a..e3789ce 100644 --- a/Sem. 13/Farm/Mouse.cpp +++ b/Sem. 13/Farm/Animals/Mouse.cpp @@ -1,12 +1,12 @@ -#include "Mouse.h"
-
-void Mouse::sayHello() const
-{
- std::cout << "Hello, I am a Mouse!" << std::endl;
-}
-
-Animal* Mouse::clone() const
-{
- Animal* newObj = new Mouse(*this); //copy constr of Mouse
- return newObj;
+#include "Mouse.h" + +void Mouse::sayHello() const +{ + std::cout << "Hello, I am a Mouse!" << std::endl; +} + +Animal* Mouse::clone() const +{ + Animal* newObj = new Mouse(*this); //copy constr of Mouse + return newObj; }
\ No newline at end of file diff --git a/Sem. 13/Farm/Mouse.h b/Sem. 13/Farm/Animals/Mouse.h index 3af9fbc..f2c70de 100644 --- a/Sem. 13/Farm/Mouse.h +++ b/Sem. 13/Farm/Animals/Mouse.h @@ -1,8 +1,8 @@ -#pragma once
-#include "Animal.h"
-class Mouse : public Animal
-{
-public:
- void sayHello() const override;
- Animal* clone() const override;
+#pragma once +#include "Animal.h" +class Mouse : public Animal +{ +public: + void sayHello() const override; + Animal* clone() const override; };
\ No newline at end of file diff --git a/Sem. 13/Farm/Farm.cpp b/Sem. 13/Farm/Collection/Farm.cpp index 73cd419..626c543 100644 --- a/Sem. 13/Farm/Farm.cpp +++ b/Sem. 13/Farm/Collection/Farm.cpp @@ -1,63 +1,63 @@ -#include "Farm.h"
-
-void Farm::free()
-{
- for (size_t i = 0; i < animalsCount; i++)
- delete animals[i]; //не се инт. какъв обект е. (вирт дестр)
- delete[] animals;
-}
-void Farm::copyFrom(const Farm& other)
-{
- animals = new Animal * [other.capacity];
- animalsCount = other.animalsCount;
- capacity = other.capacity;
-
- for (size_t i = 0; i < animalsCount; i++)
- {
- animals[i] = other.animals[i]->clone();
- }
-}
-void Farm::resize()
-{
- Animal** newCollection = new Animal * [capacity *= 2];
- for (size_t i = 0; i < animalsCount; i++)
- newCollection[i] = animals[i]; // !!не правим клониране
- delete[] animals;
- animals = newCollection;
-}
-void Farm::addAnimal(const Animal& currentAnimal)
-{
- if (animalsCount == capacity)
- resize();
- animals[animalsCount++] = currentAnimal.clone();
-}
-
-Farm::Farm()
-{
- capacity = 8;
- animalsCount = 0;
- animals = new Animal * [capacity];
-}
-Farm::Farm(const Farm& other)
-{
- copyFrom(other);
-}
-Farm& Farm::operator=(const Farm& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Farm::~Farm()
-{
- free();
-}
-
-void Farm::allSayHello() const
-{
- for (size_t i = 0; i < animalsCount; i++)
- animals[i]->sayHello();
-}
+#include "Farm.h" + +void Farm::free() +{ + for (size_t i = 0; i < animalsCount; i++) + delete animals[i]; //не се инт. какъв обект е. (вирт дестр) + delete[] animals; +} +void Farm::copyFrom(const Farm& other) +{ + animals = new Animal * [other.capacity]; + animalsCount = other.animalsCount; + capacity = other.capacity; + + for (size_t i = 0; i < animalsCount; i++) + { + animals[i] = other.animals[i]->clone(); + } +} +void Farm::resize() +{ + Animal** newCollection = new Animal * [capacity *= 2]; + for (size_t i = 0; i < animalsCount; i++) + newCollection[i] = animals[i]; // !!не правим клониране + delete[] animals; + animals = newCollection; +} +void Farm::addAnimal(const Animal& currentAnimal) +{ + if (animalsCount == capacity) + resize(); + animals[animalsCount++] = currentAnimal.clone(); +} + +Farm::Farm() +{ + capacity = 8; + animalsCount = 0; + animals = new Animal * [capacity]; +} +Farm::Farm(const Farm& other) +{ + copyFrom(other); +} +Farm& Farm::operator=(const Farm& other) +{ + if (this != &other) + { + free(); + copyFrom(other); + } + return *this; +} +Farm::~Farm() +{ + free(); +} + +void Farm::allSayHello() const +{ + for (size_t i = 0; i < animalsCount; i++) + animals[i]->sayHello(); +} diff --git a/Sem. 13/Farm/Farm.h b/Sem. 13/Farm/Collection/Farm.h index f33f244..57b1494 100644 --- a/Sem. 13/Farm/Farm.h +++ b/Sem. 13/Farm/Collection/Farm.h @@ -1,24 +1,24 @@ -#pragma once
-#include "Animal.h"
-
-class Farm
-{
- Animal** animals;
- size_t animalsCount;
- size_t capacity;
-
- void free();
- void copyFrom(const Farm& other);
- void resize();
-
-public:
- Farm();
- Farm(const Farm& other);
- Farm& operator=(const Farm& other);
- ~Farm();
-
- void addAnimal(const Animal& animal);
-
- void allSayHello() const;
-
-};
+#pragma once +#include "../Animals/Animal.h" + +class Farm +{ + Animal** animals; + size_t animalsCount; + size_t capacity; + + void free(); + void copyFrom(const Farm& other); + void resize(); + +public: + Farm(); + Farm(const Farm& other); + Farm& operator=(const Farm& other); + ~Farm(); + + void addAnimal(const Animal& animal); + + void allSayHello() const; + +}; diff --git a/Sem. 13/Farm/source.cpp b/Sem. 13/Farm/source.cpp index e5b5cf7..39062a0 100644 --- a/Sem. 13/Farm/source.cpp +++ b/Sem. 13/Farm/source.cpp @@ -1,8 +1,8 @@ #include <iostream>
-#include "Farm.h"
-#include "Dog.h"
-#include "Cat.h"
-#include "Mouse.h"
+#include "Collection/Farm.h"
+#include "Animals/Dog.h"
+#include "Animals/Cat.h"
+#include "Animals/Mouse.h"
int main()
{
|
