#include <iostream>
#include <ctime>
using namespace std;
// Dynamic Single Array of integers
#define dAry
class DynaArray {
private:
int SIZE;
int* array;
public:
DynaArray(); // Default Constructor
DynaArray(const DynaArray& dAry); // Copy Constructor
~DynaArray(); // Destructor
DynaArray& operator= (const DynaArray& dAry); // Assignment Operator
// Accessors
int getSize() const;
int getArrayElement (int index) const;
void setArrayElement (int index, int value);
inline void print () const;
// Mutators
void resetSize(int size);
void randomInit();
void create();
void init();
};
void DynaArray::create() {
array = new int [SIZE];
}
void DynaArray::init() {
for (int SIZE = 0; SIZE < SIZE; SIZE++);
DynaArray::DynaArray(); {
SIZE = 0; // set to an empty array
array = NULL; // points nowhere
}
DynaArray::DynaArray ( const DynaArray& dAry); {
this->SIZE = dAry.getSize ( );
create();
init();
// Bitwise-copy each pre-existing array element into this new array
for ( int i = 0; i < SIZE; i++) {
int array[i] = dAry.array[i];
}
}
DynaArray::~DynaArray(); {
delete [] array;
}
// Logical-Copy Assignment Operator
DynaArray& DynaArray::operator = (const DynaArray& dAry) {
this-> SIZE = dAry.get Size ( );
delete [] array;
array = new int [SIZE];
for (int i = 0; i <SIZE; i++)
array [i]=dAry.array[i];
return* this;
}
// Accessor - get size of array
int DynaArray::getSize() const {
return this->SIZE;
}
// Accessor - get an array element
int DynaArray::getArrayElement (int index) const {
// if array index is valid, then return element
if (index >= 0 && index < SIZE)
return array[index];
// else return 0
return 0;
}
// inline function - prints array
void DynaArray::print () const {
// if array is empty, print message
if (SIZE == 0) {
cout << "array empty" << endl;
return;
}
// else print array
for (int i = 0; i < SIZE; i++) {
cout << array[i] << ", ";
}
cout << "\b\b " << endl; // backspace out last comma
}
// Mutator - set an array element
void DynaArray::setArrayElement (int index, int value) {
// if array index is valid, then reset element
if (index >= 0 && index < SIZE)
array[index] = value;
}
// Mutator - Resets the size of array
// re-initializing all elements to 0
void DynaArray::resetSize(int size) {
DynaArray temp (*this);
SIZE = size
delete [] array;
array = new int [SIZE];
for (int s=0; s<SIZE; s++) {
array [s] = 0;
}
If (SIZE < temp.SIZE)
for (int s=0; s<SIZE; s++) {
array [s] = temp.array[s];
}
else
for (int s=0; s<temp.SIZE; s++) {
array [s] = temp.array[s];
}
}
// Mutator - randomly initializes all elements in array
// to integer values from 0 thru 9
void DynaArray::randomInit() {
// init all elements to random numbers from 0 thru 9
for (int i = 0; i < SIZE; i++) {
array[i] = rand()%10;
}
//Mutator - appends array at the end of array
void DynaArray::append() {
resetSize(SIZE+1);
this->array[SIZE-1] = rand()%10;
}
}
/*** MAIN FUNCTION ***/
void main () {
// Declarations
DynaArray dAry1;
DynaArray dAry2;
// Set random seed
srand(time(NULL));
// Print empty array
cout << "New Array1: \n";
cout << "dAry1 = ";
dAry1.print();
cout << endl;
// Re-size array and re-print
cout << "Resized Array1: \n";
dAry1.resetSize(10);
cout << "dAry1 = ";
dAry1.print();
cout << endl;
// randomly initialize array and re-print
cout << "Re-initialized Array1: \n";
dAry1.randomInit();
cout << "dAry1 = ";
dAry1.print();
cout << endl;
// copy dAry1 into dAry2 and print dAry2
cout << "Array2 is assigned Array1: \n";
dAry2 = dAry1;
cout << "dAry2 = ";
dAry2.print();
cout << endl;
// Re-size dAry2 & re-initialize elements randomly
dAry2.resetSize(6);
dAry2.randomInit();
// re-print both arrays
cout << "Down-sized and reinitialized Array2: \n";
cout << "dAry1 = ";
dAry1.print();
cout << "dAry2 = ";
dAry2.print();
cout << endl;
// Re-size dAry2
dAry2.resetSize(12);
// re-print dAry2
cout << "Up-sized Array2: \n";
cout << "dAry2 = ";
dAry2.print();
cout << endl;
// Append to dAry2
dAry2.append();
// re-print dAry2
cout << "Appended value to Array2: \n";
cout << "dAry2 = ";
dAry2.print();
cout << endl;
}]
the following errors i get are
error C2143: syntax error : missing ')' before 'const'
error C2059: syntax error : ')'
error C2059: syntax error : '.'
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2059: syntax error : '.'
error C2601: '=' : local function definitions are illegal
error C2601: 'getSize' : local function definitions are illegal
error C2601: 'getArrayElement' : local function definitions are illegal
error C2601: 'print' : local function definitions are illegal
error C2601: 'setArrayElement' : local function definitions are illegal
error C2601: 'resetSize' : local function definitions are illegal
error C2601: 'randomInit' : local function definitions are illegal
error C2601: 'main' : local function definitions are illegal
fatal error C1004: unexpected end of file found