「🎉」 init: hello world !
This commit is contained in:
74
ex02/main.cpp
Normal file
74
ex02/main.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <Array.hpp>
|
||||
|
||||
#define MAX_VAL 750
|
||||
int main(int, char**)
|
||||
{
|
||||
Array<int> numbers(MAX_VAL);
|
||||
int* mirror = new int[MAX_VAL];
|
||||
srand(time(NULL));
|
||||
for (int i = 0; i < MAX_VAL; i++)
|
||||
{
|
||||
const int value = rand() % 100;
|
||||
numbers[i] = value;
|
||||
mirror[i] = value;
|
||||
}
|
||||
//SCOPE
|
||||
{
|
||||
Array<int> tmp = numbers;
|
||||
Array<int> test(tmp);
|
||||
}
|
||||
|
||||
std::cout << "checking if values are the same after a copy..." << std::endl;
|
||||
for (int i = 0; i < MAX_VAL; i++)
|
||||
{
|
||||
if (mirror[i] != numbers[i])
|
||||
{
|
||||
std::cerr << "didn't save the same value!!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
std::cout << "the values are the same ! :D" << std::endl << std::endl;
|
||||
|
||||
std::cout << "trying -2:" << std::endl;
|
||||
try
|
||||
{
|
||||
numbers[-2] = 0;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
|
||||
std::cout << std::endl << "trying a correct value (15):" << std::endl;
|
||||
try
|
||||
{
|
||||
std::cout << numbers[15] << std::endl;
|
||||
numbers[15] = 0;
|
||||
std::cout << numbers[15] << std::endl;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
|
||||
std::cout << std::endl << "trying MAX_VAL:" << std::endl;
|
||||
try
|
||||
{
|
||||
numbers[MAX_VAL] = 0;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
for (int i = 0; i < MAX_VAL; i++)
|
||||
{
|
||||
std::cout << numbers[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
delete [] mirror;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user