Ok so i have to write code to construct matrices and vectors then compute some linear algebra problems like the dot product and so on. so I have written the code to construct the matrix and the vectors and so the functions, it works and does class operations however what i dont know how to do is pass the constructed matrix or vector to a different header file to do the mathematical computation.

For example: the main should look like this to do a transpose
transposing a matrix (should look like this in the main)... the same should apply for when multiplying vectors and such.

try
{
std::cout << "Answer to problem 3:" <<endl;
Matrix m(3,3); //constructs a 3x3 matrix
m.set(0,0,2); //enters a value into address 0,0 in the 2 d matrix
m.set(0,1,4);
m.set(0,2,1);
...etc...

Matrix * mtran = transpose(m);

mtran ->print();
}

my question is this... if i create a file called LinearAlgebra.h and the LinearAlgebra.cpp file... what will "transpose(m)" look like in the .h and .cpp file

below is my code for the matrix.h and matrix.cpp file if that helps at all.

Thanks

//matrix.h

using namespace std;

class matrix
{
private:
	int numRows;
	int numCols;
	int **matrixArr;
public:
	matrix();
	~matrix();
	void matrixConstruct(int rows, int cols);
	int getRows();
	int getCols();
	void set(int row, int col, int val);
	int get(int row, int col);
	void print();
};

// matrix source file matrix.cc
#include "stdafx.h"
#include <stdexcept>
#include <iostream>
#include "matrix.h"

using namespace std;

matrix::matrix()
{
	numRows = 3;
	numCols = 3;

	int **matrix = new int* [numRows];
	for(int i = 0; i < numRows; i++)
	{
		matrix[i] = new int [numCols];
	}
	for(int i=0; i<numRows; i++)
	{
		for(int j=0; j<numCols; j++)
		{
			matrix[i][j]= 0;
		}
	}

	matrixArr = matrix;
}

matrix::~matrix()
{
	delete[] matrixArr;
}

void matrix::matrixConstruct(int rows, int cols)
{
	numRows = rows;
	numCols = cols;

	int **matrix = new int* [numRows];
	for(int i = 0; i < numRows; i++)
	{
		matrix[i] = new int [numCols];
	}
	for(int i=0; i<numRows; i++)
	{
		for(int j=0; j<numCols; j++)
		{
			matrix[i][j]= 0;
		}
	}

	matrixArr = matrix;
}

void matrix::set(int row, int col, int val)
{
	matrixArr[row][col] = val;
	cout<<"set"<<endl;
}

int matrix::get(int row, int col)
{
	return matrixArr[row][col];
}

int matrix::getRows()
{
	return numRows;
}

int matrix::getCols()
{
	return numCols;
}

void matrix::print()
{
	for(int i = 0; i<numRows; i++)
	{
		for(int j = 0; j<numCols; j++)
		{
			cout<<matrixArr[i][j]<<" ";
		}
		cout<<endl;
	}
}

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.