ACEM PORTAL

::Community of ACEM students::
 
HomeHome  CalendarCalendar  GalleryGallery  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  
Search
 
 

Display results as :
 
Rechercher Advanced Search
Poll
Latest topics
» Primer Imperio-Torre De Control Mp3
Fri Feb 14, 2014 1:20 pm by bakakali

» LTSP Deployment
Sat May 09, 2009 11:31 am by Santos

» GTA SanAndreas 64kB!!!
Tue May 05, 2009 2:56 pm by Santos

» EPL names..
Thu Apr 30, 2009 4:26 pm by Kxhitiz

» Google logo.
Thu Apr 30, 2009 4:22 pm by Kxhitiz

» Google logo.
Thu Apr 30, 2009 11:36 am by Santos

» the longest website in the world haha
Wed Apr 29, 2009 8:50 am by Kxhitiz

» Ubuntu 9.04 Jaunty Jackalope.
Sat Apr 25, 2009 12:31 am by Santos

» Program to display text with defined cursor position and defined color
Sat Apr 25, 2009 12:11 am by Santos

Navigation
 Portal
 Index
 Fun
 Memberlist
 Profile
 FAQ
 Search
September 2017
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
CalendarCalendar

Share | 
 

 Matrix Operation Using Operator Overloading

View previous topic View next topic Go down 
AuthorMessage
Kxhitiz
Admin
Admin
avatar

Posts : 24
Join date : 2009-03-06

PostSubject: Matrix Operation Using Operator Overloading   Sun Mar 08, 2009 10:25 pm

#include<iostream.h>
#include<conio.h>

class matrix{
private:
int mat[5][5];
int row;
int column;
public:
matrix(int,int);
matrix(matrix&);
void getdata();
matrix operator-(matrix);
matrix operator+(matrix);
matrix operator*(matrix);
void display();
};

matrix::matrix(int r,int c)
{
cout<<"constructor to initiliaze no of rows and columns"<<endl;
row=r;column=c;
}

matrix::matrix(matrix& m)
{
row=m.row;
column=m.column;

cout<<"Copy constructor"<<endl;
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
mat[i][j]=m.mat[i][j];
}
}
}

void matrix::getdata()
{
cout<<"Value input:"<<endl;
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
cout<<"Value("<<i+1<<")("<<j+1<<"):";
cin>>mat[i][j];
}
}


}

matrix matrix::operator+(matrix a)
{
cout<<"Addition operator"<<endl;

matrix temp(row,column);

for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
temp.mat[i][j]=mat[i][j]+a.mat[i][j];
}
}
return temp;
}

matrix matrix::operator-(matrix a)
{
cout<<"Subtraction operator"<<endl;

matrix temp(row,column);

for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
temp.mat[i][j]=mat[i][j]-a.mat[i][j];
}
}
return temp;
}

matrix matrix::operator*(matrix a)
{
cout<<"Multiplaction operator"<<endl;

matrix temp(row,column);

for (int i=0;i<row;i++)
{
for (int j=0;j<column;j++)
{
temp.mat[i][j]=0;
for(int k=0;k<column;k++)
{
temp.mat[i][j]=temp.mat[i][j]+(mat[i][k]*a.mat[k][j]);
}
}
}

return temp;
}

void matrix::display()
{
cout<<"The matrix is "<<endl;
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<endl;
}
}

int main()
{
clrscr();
matrix m1(2,2),m2(2,2),m3(2,2);

m1.getdata();
m2.getdata();

m3=m1+m2;
m3.display();

m3=m1-m2;
m3.display();

m3=m1*m2;
m3.display();

getch();
return 0;
}
Back to top Go down
View user profile http://advanced.chforum.net
 
Matrix Operation Using Operator Overloading
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Operation Z-Day
» Matrix
» Matrix problem with new Battlenet
» The Final Fight: Operation Phoenix 2nd Demo Released
» A Stroke of Fate: Operation Valkyrie

Permissions in this forum:You cannot reply to topics in this forum
ACEM PORTAL :: Programming :: C & C++-
Jump to: