-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (85 loc) · 2.57 KB
/
Copy pathmain.cpp
File metadata and controls
107 lines (85 loc) · 2.57 KB
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
#include <Array.hpp>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include "defines.hpp"
int
main (void)
{
print (YELLOW_BOLD TITTLE "CPP Molule 07 - ex02" RESET);
print (YELLOW SUB_TITTLE "Constructors\n" RESET);
{
Array<int> array1 (500);
Array<int> array2;
print (PURPLE "Array1 size: " RESET << array1.size ());
print (PURPLE "Array2 size: " RESET << array2.size ());
try
{
Array<int> array3 (-42);
}
catch (std::exception &e)
{
print (e.what ());
}
}
print (YELLOW SUB_TITTLE "Subscript operator\n" RESET);
{
const char *message = "Batman";
Array<std::string> array (strlen (message));
for (size_t i = 0; message[i]; i++)
array[i] = message[i];
for (size_t i = 0; i < array.size (); i++)
print (PURPLE "array[" << i << "] = " RESET << array[i]);
try
{
print (PURPLE "array[42] = " RESET << array[42]);
}
catch (std::exception &e)
{
print (e.what ());
}
}
print (YELLOW SUB_TITTLE "Copy constructor\n" RESET);
{
Array<std::string> array (3);
const char *messages[] = { "Hello", "World", "!" };
for (size_t i = 0; i < array.size (); i++)
array[i] = messages[i];
{
Array<std::string> copy (array);
for (size_t i = 0; i < array.size (); i++)
print (PURPLE "array[" << i << "] = " RESET << array[i]);
std::cout << std::endl;
for (size_t i = 0; i < copy.size (); i++)
print (PURPLE "copy[" << i << "] = " RESET << copy[i]);
std::cout << std::endl;
print ("copy[2] = \"Batman\"" << ";" << RESET);
std::cout << std::endl;
copy[2] = "Batman";
print (PURPLE "copy[2] = " RESET << copy[2]);
print (PURPLE "array[2] = " RESET << array[2]);
}
}
print (YELLOW SUB_TITTLE "Assigment operator\n" RESET);
{
Array<std::string> array (3);
const char *messages[] = { "Hello", "World", "!" };
for (size_t i = 0; i < array.size (); i++)
array[i] = messages[i];
{
Array<std::string> copy;
copy = array;
for (size_t i = 0; i < array.size (); i++)
print (PURPLE "array[" << i << "] = " RESET << array[i]);
std::cout << std::endl;
for (size_t i = 0; i < copy.size (); i++)
print (PURPLE "copy[" << i << "] = " RESET << copy[i]);
std::cout << std::endl;
print ("copy[2] = \"Batman\"" << ";" << RESET);
std::cout << std::endl;
copy[2] = "Batman";
print (PURPLE "copy[2] = " RESET << copy[2]);
print (PURPLE "array[2] = " RESET << array[2]);
}
}
}