The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I need help finishing this c++ program. I'm close to finishing but am having trouble getting all of the components to work together properly. Matrix.h should be finished with but I am unsure. I need help finishing Matrix.cpp and p1.cpp.If you could also please explain what I have done wrong and what you have done to fix, that would be extremely helpful. This is all done on a linux server and I need it all done to the specification of the project please. If you have any question please ask me.
These are some of the error i get when compiling:
In function `Matrix::Matrix(Matrix const&)':
Matrix.cpp:(.text+0x138): undefined reference to `Matrix::at(unsigned int, unsigned int) const'
/tmp/cc6aGECy.o: In function `Matrix::add(Matrix const&) const':
Matrix.cpp:(.text+0x28b): undefined reference to `Matrix::at(unsigned int, unsigned int) const'
/tmp/cc6aGECy.o: In function `Matrix::subtract(Matrix const&) const':
Matrix.cpp:(.text+0x419): undefined reference to `Matrix::at(unsigned int, unsigned int) const'
/tmp/cc6aGECy.o: In function `Matrix::multiply(Matrix const&) const':
Matrix.cpp:(.text+0x5db): undefined reference to `Matrix::at(unsigned int, unsigned int) const'
I know the multiply two matrices together needs to be fixed but I'm bot sure how.
#include "Matrix.h"
using namespace std;
Matrix::Matrix(uint rows, uint cols) : rows(rows), colums(cols)
{
mat = new double*[rows];
for(int i = 0; i < rows; i++)
{
mat[i] = new double[cols];
}
}//Constructor
Matrix::Matrix(const Matrix& m)
{
rows = m.rows;
colums = m.colums;
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] = m.at(i,j);
}
}
}//Copy Constructor
Matrix::~Matrix()
{
delete [] mat;
}//Deconstructor
Matrix Matrix::add(double s) const
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] += s;
}
}
return *this;
}//add scalar to the matrix
Matrix Matrix::add(const Matrix & m) const
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] += m.at(i,j);
}
}
return *this;
}//add this matrix and another
Matrix Matrix::subtract(double s) const
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] -= s;
}
}
return *this;
}//subtract scalar to the matrix
Matrix Matrix::subtract(const Matrix & m) const
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] -= m.at(i,j);
}
}
return *this;
}//subtract this matrix and another
Matrix Matrix::multiply(double s) const
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] *= s;
}
}
return *this;
}//multiply scalar to the matrix
Matrix Matrix::multiply(const Matrix & m) const
{
int r = m.numRows();
int c = m.numCols();
Matrix temp(rows,c);
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < c;j++)
{
mat[i][j] *= m.at(i,j);
}
}
return *this;
}//multiply this matrix and another
Matrix Matrix::divide(double s) const
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
mat[i][j] /= s;
}
}
return *this;
}//divide scalar to the matrix
/*
Matrix t() const
{
Matrix m;
m.rows = colums;
m.colums = rows;
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < colums;j++)
{
m.at(i,j) = mat[j][i];
}
}
*this = m;
return *this;
}//transpose of this matrix
*/
/*
double & at(uint row, uint col)
{
return mat[row][col];
}// get/set element at row,col
const double & at (uint row, uint col) const
{
return mat[row][col];
}// get element at row,col (when using a const object)
*/
Matrix Matrix::operator +(int s)
{
return add(s);
}
Matrix Matrix::operator +(Matrix& s)
{
return add(s);
}
Matrix Matrix::operator -(int s)
{
return subtract(s);
}
Matrix Matrix::operator -(Matrix& s)
{
return subtract(s);
}
Matrix Matrix::operator *(int s)
{
return multiply(s);
}
Matrix Matrix::operator *(Matrix& s)
{
return multiply(s);
}
Matrix Matrix::operator /(int s)
{
return divide(s);
}
I did't add the p1.cpp because I havn't done anything in it yet.
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly