first commit

This commit is contained in:
2026-03-05 13:16:26 +01:00
commit 1b2bf174e8
164 changed files with 35594 additions and 0 deletions

118
Lab5/array.h Normal file
View File

@@ -0,0 +1,118 @@
//##################################################################
// 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 <iostream.h>
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 ; i++)
buffer[i] = src.buffer[i];
}
//################################################################
// Operator overload
// Allows to assign a Array to another
//================================================================
void Array::operator = (const Array &src) {
delete [] buffer;
size = src.size;
try {
buffer = new int[size];
}catch(MemoryError &e){ e.Print(); }