forked from shalevf6/AP-scriptRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntArray.cpp
More file actions
64 lines (59 loc) · 1.33 KB
/
IntArray.cpp
File metadata and controls
64 lines (59 loc) · 1.33 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
#include <iostream>
#include "IntArray.h"
using namespace std;
/*
* constructor of new int array
* intArray - points of the beginning of the new array.
* size - the size of the array.
* name - the given name of the array.
* type - the type of the array, set to be int.
*/
IntArray::IntArray(int *intArray, int size,string name,string type): ArrayVariable(size,name,type)
{
m_intArray = (IntVariable**) malloc(sizeof(IntVariable) * size);
int i;
for (i = 0; i < size; i++)
{
m_intArray[i] = new IntVariable(intArray[i],"","int");
}
}
/*
* destructor of the array.
*/
IntArray::~IntArray()
{
int i;
for (i = 0; i < ArrayVariable::m_arraySize; i++)
delete(m_intArray[i]);
free(m_intArray);
}
/*
* returns a pointer of an element in the array.
* index - the given index of the element.
*/
IntVariable* IntArray::getIntElement(int index)
{
return m_intArray[index];
}
/*
* A private function to print the array.
*/
ostream & IntArray::Show(ostream & out)const
{
int i;
cout << *m_intArray[0];
int length = ArrayVariable::m_arraySize;
for (i = 1; i < length; i++)
{
cout << ", ";
cout << *m_intArray[i];
}
cout << "\n";
}
/*
* printing a given array with the right format.
*/
ostream & operator<<(ostream& out,const IntArray & iA)
{
iA.Show(out);
}