-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
111 lines (91 loc) · 3.31 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wcorrea- <wcorrea-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 15:24:39 by wcorrea- #+# #+# */
/* Updated: 2023/07/26 09:14:27 by wcorrea- ### ########.fr */
/* */
/* ************************************************************************** */
#include "Dog.hpp"
#include "Cat.hpp"
#include "WrongCat.hpp"
void pressEnter(void)
{
std::cout << std::endl << "press ENTER to continue" << std::endl;
std::cin.ignore();
std::cout << "\033c";
}
void titleHeader(const std::string& message)
{
std::cout << "\033c";
int standartSize = 34;
int messageSize = message.length();
int spaces = (standartSize - messageSize) / 2;
std::cout << "************************************" << std::endl << "*";
for (int i = 0; i < spaces; i++)
std::cout << " ";
std::cout << message;
for (int i = 0; i < spaces; i++)
std::cout << " ";
std::cout << "*" << std::endl << "************************************" << std::endl << std::endl;
}
int main()
{
titleHeader("INITIALIZE DEFINED OBJECTS");
const Animal* j = new Dog();
const Animal* i = new Cat();
std::cout << j->getType() << " " << std::endl;
std::cout << i->getType() << " " << std::endl;
i->makeSound();
j->makeSound();
delete j;
delete i;
pressEnter();
titleHeader("INITIALIZE ABSTRACT OBJECTS");
std::cout << "You can't initialize an abstract object." << std::endl;
// Animal test;
pressEnter();
titleHeader("ANIMAL ARRAY TEST");
Animal *animals[6] =
{
new Dog(), new Dog(), new Dog(),
new Cat(), new Cat(), new Cat()
};
for (int i = 0; i < 6; i++)
{
std::cout << std::endl << "Destroy Animal " << i + 1 << std::endl;
delete animals[i];
}
pressEnter();
titleHeader("BASIC COPY TEST");
{
Dog basic;
Dog tmp = basic;
std::cout << std::endl << "Basic's Brain Adress: " << basic.getBrain() << std::endl;
std::cout << "Tmp's Brain Adress : " << tmp.getBrain() << std::endl << std::endl;
}
pressEnter();
titleHeader("CAT DEEP COPY TEST");
Cat *original = new Cat();
Cat *copy = new Cat(*original);
std::cout << std::endl << "Original's Brain Adress: " << original->getBrain() << std::endl;
original->getBrain()->showIdeas();
delete original;
std::cout << std::endl << "Copy's Brain Adress: " << copy->getBrain() << std::endl;
copy->getBrain()->showIdeas();
delete copy;
pressEnter();
titleHeader("DOG DEEP COPY TEST");
Dog *originalDog = new Dog();
Dog *copyDog = new Dog(*originalDog);
std::cout << std::endl << "Original's Brain Adress: " << originalDog->getBrain() << std::endl;
originalDog->getBrain()->showIdeas();
delete originalDog;
std::cout << std::endl << "Copy's Brain Adress: " << copyDog->getBrain() << std::endl;
copyDog->getBrain()->showIdeas();
delete copyDog;
pressEnter();
}