-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharreglo.cc
63 lines (55 loc) · 1.28 KB
/
arreglo.cc
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
#include <iostream>
#include "arreglo.h"
#include "simbolo.h"
using namespace std;
#define ERROR_SIZE_1 "Error: acceso inválido a posición "
#define ERROR_SIZE_2 " en arreglo de tamaño "
#define ERROR_SIZE_CONSTRUCTOR "Tamaño inválido. No se pudo crear el arreglo."
arreglo::arreglo(const int & size)
{
if( size > 0 )
{
dato_ = new simbolo[size];
size_ = new int;
*size_ = size;
}
else
cout << ERROR_SIZE_CONSTRUCTOR << endl;
}
arreglo::~arreglo()
{
if( dato_ )
delete[] dato_;
if( size_ )
delete size_;
}
simbolo & arreglo::operator[](const unsigned short pos)
{
if( pos >= *size_ || pos < 0 )
{
cout << ERROR_SIZE_1
<< pos
<< ERROR_SIZE_2
<< *size_
<< '.'
<< endl;
}
return dato_[pos];
}
simbolo & arreglo::obtener_dato(const unsigned short pos)
{
if( pos >= *size_ || pos < 0 )
{
cout << ERROR_SIZE_1
<< pos
<< ERROR_SIZE_2
<< *size_
<< '.'
<< endl;
}
return dato_[pos];
}
int arreglo::obtener_size() const
{
return *size_;
}