Click here to Skip to main content
15,897,518 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionConnect to IRC server Pin
Thilek3-Jan-10 20:55
Thilek3-Jan-10 20:55 
AnswerRe: Connect to IRC server Pin
ThatsAlok3-Jan-10 22:09
ThatsAlok3-Jan-10 22:09 
AnswerRe: Connect to IRC server Pin
Moak3-Jan-10 23:12
Moak3-Jan-10 23:12 
GeneralRe: Connect to IRC server Pin
Thilek4-Jan-10 19:25
Thilek4-Jan-10 19:25 
Questiondisable CString value Pin
Rakesh53-Jan-10 20:41
Rakesh53-Jan-10 20:41 
AnswerRe: disable CString value Pin
KingsGambit3-Jan-10 20:50
KingsGambit3-Jan-10 20:50 
AnswerRe: disable CString value Pin
Cedric Moonen3-Jan-10 20:55
Cedric Moonen3-Jan-10 20:55 
AnswerRe: disable CString value Pin
«_Superman_»3-Jan-10 21:12
professional«_Superman_»3-Jan-10 21:12 
AnswerRe: disable CString value Pin
Nelek3-Jan-10 22:02
protectorNelek3-Jan-10 22:02 
AnswerRe: disable CString value Pin
Rajesh R Subramanian3-Jan-10 22:15
professionalRajesh R Subramanian3-Jan-10 22:15 
AnswerRe: disable CString value Pin
Michael Schubert4-Jan-10 5:10
Michael Schubert4-Jan-10 5:10 
GeneralRe: disable CString value Pin
CPallini4-Jan-10 11:36
mveCPallini4-Jan-10 11:36 
GeneralRe: disable CString value Pin
Michael Schubert4-Jan-10 22:00
Michael Schubert4-Jan-10 22:00 
GeneralRe: disable CString value Pin
CPallini4-Jan-10 22:27
mveCPallini4-Jan-10 22:27 
QuestionAssertion error in SetWindowPos() Pin
Anu_Bala3-Jan-10 19:01
Anu_Bala3-Jan-10 19:01 
AnswerRe: Assertion error in SetWindowPos() Pin
KingsGambit3-Jan-10 19:34
KingsGambit3-Jan-10 19:34 
AnswerRe: Assertion error in SetWindowPos() Pin
«_Superman_»3-Jan-10 19:36
professional«_Superman_»3-Jan-10 19:36 
GeneralRe: Assertion error in SetWindowPos() Pin
Anu_Bala3-Jan-10 20:09
Anu_Bala3-Jan-10 20:09 
GeneralRe: Assertion error in SetWindowPos() Pin
KingsGambit3-Jan-10 20:22
KingsGambit3-Jan-10 20:22 
GeneralRe: Assertion error in SetWindowPos() Pin
Anu_Bala3-Jan-10 22:13
Anu_Bala3-Jan-10 22:13 
QuestionMatrix class h Pin
richard cyper3-Jan-10 13:19
richard cyper3-Jan-10 13:19 
Please help with this code.Am trying to design a Matrix class with the following operation Addition, Multiplication, Subtraction and division.The code compile , But my result is incorrect
.please if someone can to solve this incorrect result.
This is my code Below.


#include <iostream>
using namespace std;

//member function of matrix class
class matrix{

public:


matrix();
matrix(int m,int n);

int getRow();
int getCol();

double& operator()(int, int);

//the operator used in the matrix class which are (addition operator, multiplication operator,substraction operator, and divide operator).
friend ostream& operator<<(ostream& os, matrix& m);
matrix operator + (matrix&);
matrix operator * (matrix&);
matrix operator - (matrix&);
matrix operator / (matrix&);

private:
void init(int, int);
int nrows,ncols;
double *data;
};

matrix::matrix(){
init(1,1);
}

matrix::matrix(int m, int n){
init(m,n);
}

//destructor to delete the used dynamic memory.
void matrix::init(int m, int n){
nrows=m;
ncols=n;
data= new double[m*n];
for(int i=0; i<m*n; i++)
data[i]=0;
}

int matrix::getRow() { return nrows;}

int matrix::getCol() { return ncols;}

double& matrix::operator ()(int r, int c){
if (r <0 || r> nrows){
cout<<"Illegal row index";
return data[0];
}
else if (c <0 || c > ncols){
cout<<"Illegal Column Index:";
return data[0];
}
else return data[r*ncols+c];
}


ostream& operator<<(ostream& os, matrix &m){
int mval=m.getRow();
int nval=m.getCol();
for(int i=0; i<mval; i++){
for(int j=0; j < nval; j++)
os<<m(i,j)<<" ";
os<<endl;
}
return os;
}

//To compute the summation
matrix matrix::operator+(matrix& a){
matrix sum(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
sum(i,j) = (i,j) + a(i,j);
return sum;
}
//To compute the multiplication
matrix matrix::operator*(matrix& a){
matrix product(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
product(i,j) = (i,j) * a(i,j);
return product;
}

//To compute the substraction
matrix matrix::operator-(matrix& a){
matrix difference(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
difference(i,j) = (i,j) - a(i,j);
return difference;
}

//To compute the division
matrix matrix::operator/(matrix& a){
matrix divide(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
divide(i,j) = (i,j) / a(i,j);
return divide;
}


int main(){

//the array of matrix a
matrix a(2,2);
a(1,1)=5.0;
a(0,0)=6.0;
a(0,1)=7.0;
a(1,0)=8.0;


cout<<"matrix a\n";
cout<<a<<endl;

//the array of matrix b
matrix b(2,2);
b(0,0) = 5.0;
b(0,1) = 5.0;
b(1,0) = 5.0;
b(1,1) = 5.0;
cout<<"matrix b\n";
cout<<b<<endl;

matrix c,d,e,f;

//to compute the operation of the matrix (addition, multiplication, substraction and division).
c=a+b;
d=a*b;
e=a-b;
f=a/b;


//to Display the result operation of the matrix (addition, multiplication, substraction and division).
cout<<"matrix a+b \n";
cout<<c<<endl;
cout <<"\n\n";
cout<<"matrix a*b\n";
cout<<d<<endl;
cout<<"matrix a-b\n";
cout<<e<<endl;
cout <<"\n\n";
cout<<"matrix a/b\n";
cout<<f<<endl;


system("pause");
return 0;
}
AnswerRepost. Pin
CPallini3-Jan-10 13:44
mveCPallini3-Jan-10 13:44 
AnswerRe: Matrix class h Pin
Cedric Moonen3-Jan-10 20:27
Cedric Moonen3-Jan-10 20:27 
AnswerRe: Matrix class h Pin
Alan Balkany6-Jan-10 4:00
Alan Balkany6-Jan-10 4:00 
QuestionDrawing 32 bit bitmaps Pin
softwaremonkey3-Jan-10 10:53
softwaremonkey3-Jan-10 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.