//################################################################## // LAB 5 // ADVANCED PROGRAMMING IN C++ // MATRIX/ARRAY WITH TRY-CATCH //================================================================== // array.h // CLASS IMPLEMENTATION AND DEFINITION FOR // THE ARRAY // Christian Ohlsson // Daniel Alfredsson // Karlstad 990927 //================================================================== #include class Array { private: int size; //The size of the Array int *buffer; //Pointer to an int-buffer public: ~Array(); Array(const int s=0); Array(const Array &src); void operator = (const Array &src); Array Array::operator +(const Array &src); int &operator [] (int index) const; int getSize() const; }; //################################################################ // Constructor // Creates a new Array //================================================================ Array::Array(const int s) { try { buffer = new int[s]; }catch(MemoryError &e){ e.Print(); } size= s; } //################################################################ // Constructor // Copys an array //================================================================ Array::Array(const Array &src) { size = src.size; try { buffer = new int[size]; }catch(MemoryError &e){ e.Print(); } for(int i=0 ; i= size) throw RangeError(); return buffer[index]; } //################################################################ // Operator overload // Allows to add a Array to another //================================================================ Array Array::operator + (const Array &src) { if(src.size != getSize()) throw SizeError(); Array tmp(size); for(int i=0 ; i> (istream &is, Array &v) { for(int l=0 ; l> v[l]; return is; } //################################################################ // Operator overload // Prints out an Array, using STDOUT //================================================================ ostream &operator << (ostream &os, const Array &v) { for(int k=0 ; k