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