From e012bcac0a5c5fc804fbeadb0e8ab382c5e6feb7 Mon Sep 17 00:00:00 2001 From: angeld55 Date: Tue, 31 May 2022 00:56:24 +0300 Subject: split in to folders --- Sem. 13/Farm/Animal.h | 11 ------- Sem. 13/Farm/Animals/Animal.h | 11 +++++++ Sem. 13/Farm/Animals/Cat.cpp | 12 ++++++++ Sem. 13/Farm/Animals/Cat.h | 8 +++++ Sem. 13/Farm/Animals/Dog.cpp | 12 ++++++++ Sem. 13/Farm/Animals/Dog.h | 8 +++++ Sem. 13/Farm/Animals/Mouse.cpp | 12 ++++++++ Sem. 13/Farm/Animals/Mouse.h | 8 +++++ Sem. 13/Farm/Cat.cpp | 12 -------- Sem. 13/Farm/Cat.h | 8 ----- Sem. 13/Farm/Collection/Farm.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ Sem. 13/Farm/Collection/Farm.h | 24 +++++++++++++++ Sem. 13/Farm/Dog.cpp | 12 -------- Sem. 13/Farm/Dog.h | 8 ----- Sem. 13/Farm/Farm.cpp | 63 ---------------------------------------- Sem. 13/Farm/Farm.h | 24 --------------- Sem. 13/Farm/Mouse.cpp | 12 -------- Sem. 13/Farm/Mouse.h | 8 ----- Sem. 13/Farm/source.cpp | 8 ++--- 19 files changed, 162 insertions(+), 162 deletions(-) delete mode 100644 Sem. 13/Farm/Animal.h create mode 100644 Sem. 13/Farm/Animals/Animal.h create mode 100644 Sem. 13/Farm/Animals/Cat.cpp create mode 100644 Sem. 13/Farm/Animals/Cat.h create mode 100644 Sem. 13/Farm/Animals/Dog.cpp create mode 100644 Sem. 13/Farm/Animals/Dog.h create mode 100644 Sem. 13/Farm/Animals/Mouse.cpp create mode 100644 Sem. 13/Farm/Animals/Mouse.h delete mode 100644 Sem. 13/Farm/Cat.cpp delete mode 100644 Sem. 13/Farm/Cat.h create mode 100644 Sem. 13/Farm/Collection/Farm.cpp create mode 100644 Sem. 13/Farm/Collection/Farm.h delete mode 100644 Sem. 13/Farm/Dog.cpp delete mode 100644 Sem. 13/Farm/Dog.h delete mode 100644 Sem. 13/Farm/Farm.cpp delete mode 100644 Sem. 13/Farm/Farm.h delete mode 100644 Sem. 13/Farm/Mouse.cpp delete mode 100644 Sem. 13/Farm/Mouse.h diff --git a/Sem. 13/Farm/Animal.h b/Sem. 13/Farm/Animal.h deleted file mode 100644 index 3911d49..0000000 --- a/Sem. 13/Farm/Animal.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include -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/Animals/Animal.h b/Sem. 13/Farm/Animals/Animal.h new file mode 100644 index 0000000..9c55bce --- /dev/null +++ b/Sem. 13/Farm/Animals/Animal.h @@ -0,0 +1,11 @@ +#pragma once +#include +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/Animals/Cat.cpp b/Sem. 13/Farm/Animals/Cat.cpp new file mode 100644 index 0000000..8716d4b --- /dev/null +++ b/Sem. 13/Farm/Animals/Cat.cpp @@ -0,0 +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; +} \ No newline at end of file diff --git a/Sem. 13/Farm/Animals/Cat.h b/Sem. 13/Farm/Animals/Cat.h new file mode 100644 index 0000000..8d60fd1 --- /dev/null +++ b/Sem. 13/Farm/Animals/Cat.h @@ -0,0 +1,8 @@ +#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/Animals/Dog.cpp b/Sem. 13/Farm/Animals/Dog.cpp new file mode 100644 index 0000000..879957f --- /dev/null +++ b/Sem. 13/Farm/Animals/Dog.cpp @@ -0,0 +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; +} \ No newline at end of file diff --git a/Sem. 13/Farm/Animals/Dog.h b/Sem. 13/Farm/Animals/Dog.h new file mode 100644 index 0000000..2c69e03 --- /dev/null +++ b/Sem. 13/Farm/Animals/Dog.h @@ -0,0 +1,8 @@ +#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/Animals/Mouse.cpp b/Sem. 13/Farm/Animals/Mouse.cpp new file mode 100644 index 0000000..e3789ce --- /dev/null +++ b/Sem. 13/Farm/Animals/Mouse.cpp @@ -0,0 +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; +} \ No newline at end of file diff --git a/Sem. 13/Farm/Animals/Mouse.h b/Sem. 13/Farm/Animals/Mouse.h new file mode 100644 index 0000000..f2c70de --- /dev/null +++ b/Sem. 13/Farm/Animals/Mouse.h @@ -0,0 +1,8 @@ +#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/Cat.cpp b/Sem. 13/Farm/Cat.cpp deleted file mode 100644 index 4bb833a..0000000 --- a/Sem. 13/Farm/Cat.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#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/Cat.h deleted file mode 100644 index 1e1525d..0000000 --- a/Sem. 13/Farm/Cat.h +++ /dev/null @@ -1,8 +0,0 @@ -#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/Collection/Farm.cpp b/Sem. 13/Farm/Collection/Farm.cpp new file mode 100644 index 0000000..626c543 --- /dev/null +++ b/Sem. 13/Farm/Collection/Farm.cpp @@ -0,0 +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(); +} diff --git a/Sem. 13/Farm/Collection/Farm.h b/Sem. 13/Farm/Collection/Farm.h new file mode 100644 index 0000000..57b1494 --- /dev/null +++ b/Sem. 13/Farm/Collection/Farm.h @@ -0,0 +1,24 @@ +#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/Dog.cpp b/Sem. 13/Farm/Dog.cpp deleted file mode 100644 index f44692c..0000000 --- a/Sem. 13/Farm/Dog.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#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/Dog.h deleted file mode 100644 index 26fc187..0000000 --- a/Sem. 13/Farm/Dog.h +++ /dev/null @@ -1,8 +0,0 @@ -#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/Farm.cpp b/Sem. 13/Farm/Farm.cpp deleted file mode 100644 index 73cd419..0000000 --- a/Sem. 13/Farm/Farm.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#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/Farm.h deleted file mode 100644 index f33f244..0000000 --- a/Sem. 13/Farm/Farm.h +++ /dev/null @@ -1,24 +0,0 @@ -#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; - -}; diff --git a/Sem. 13/Farm/Mouse.cpp b/Sem. 13/Farm/Mouse.cpp deleted file mode 100644 index a6dc30a..0000000 --- a/Sem. 13/Farm/Mouse.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#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/Mouse.h deleted file mode 100644 index 3af9fbc..0000000 --- a/Sem. 13/Farm/Mouse.h +++ /dev/null @@ -1,8 +0,0 @@ -#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/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 -#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() { -- cgit v1.3.1-23-gd82d