first commit
This commit is contained in:
120
Lab5/matrix.h
Normal file
120
Lab5/matrix.h
Normal file
@@ -0,0 +1,120 @@
|
||||
//##################################################################
|
||||
|
||||
// LAB 5
|
||||
|
||||
// ADVANCED PROGRAMMING IN C++
|
||||
|
||||
// MATRIX/ARRAY WITH TRY-CATCH
|
||||
|
||||
//==================================================================
|
||||
|
||||
// matrix.h
|
||||
|
||||
// CLASS IMPLEMENTATION AND DEFINITION FOR
|
||||
|
||||
// THE MATRIX
|
||||
|
||||
// Christian Ohlsson
|
||||
|
||||
// Daniel Alfredsson
|
||||
|
||||
// Karlstad 990907
|
||||
|
||||
//==================================================================
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "except.h"
|
||||
|
||||
#include "array.h"
|
||||
|
||||
|
||||
|
||||
class Matrix {
|
||||
|
||||
private:
|
||||
|
||||
int cols, rows; //# of cols and rows in the matrix
|
||||
|
||||
Array *myMatrix; //Array-pointer to our matrix
|
||||
|
||||
public:
|
||||
|
||||
void Matrix::operator = (const Matrix &src);
|
||||
|
||||
int getCols() const { return cols;};
|
||||
|
||||
int getRows() const { return rows;};
|
||||
|
||||
Array &Matrix::operator [] (int index) const;
|
||||
|
||||
Matrix(const Matrix &src);
|
||||
|
||||
Matrix(int cols, int rows);
|
||||
|
||||
~Matrix();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
//################################################################
|
||||
|
||||
// Constructor
|
||||
|
||||
// Creates a new Matrix with 'c' columns and 'r' rows
|
||||
|
||||
//================================================================
|
||||
|
||||
Matrix::Matrix(int c, int r) {
|
||||
|
||||
try {
|
||||
|
||||
myMatrix = new Array[r];
|
||||
|
||||
}catch(MemoryError &e){ e.Print(); }
|
||||
|
||||
|
||||
|
||||
for(int i=0; i < c; i++)
|
||||
|
||||
myMatrix[i] = Array(c);
|
||||
|
||||
cols = c;
|
||||
|
||||
rows = r;
|
||||
|
||||
}
|
||||
|
||||
//################################################################
|
||||
|
||||
// Constructor
|
||||
|
||||
// Creates a new copy of a Matrix
|
||||
|
||||
//================================================================
|
||||
|
||||
Matrix::Matrix(const Matrix &src) {
|
||||
|
||||
cols = src.cols;
|
||||
|
||||
rows = src.rows;
|
||||
|
||||
int i,j;
|
||||
|
||||
try {
|
||||
|
||||
myMatrix = new Array[rows];
|
||||
|
||||
}catch(MemoryError &e){ e.Print(); }
|
||||
|
||||
|
||||
|
||||
for(i=0; i < cols; i++)
|
||||
|
||||
myMatrix[i] = Array(cols);
|
||||
|
||||
for(i=0 ; i < cols ; i++)
|
||||
|
||||
Reference in New Issue
Block a user