MATRIX' CLASS OF SIZE m X n, OVERLOAD THE '+' OPERATOR TO ADD TWO MATRIX OBJECTS
hello friends....
TAKE THE FIRST STEP TO KNOWLEDGE FRIENDS BECAUSE KNOWLEDGE IS FREE.
/* CREATE A 'MATRIX' CLASS OF SIZE m X n, OVERLOAD THE '+' OPERATOR TO ADD TWO MATRIX OBJECTS. WRITE A FUNCTION IMPLEMENT IT. */
#include<iostream.h>
#include<conio.h>
class matrix
{
int i,j,m[3][3];
public:
void getdata()
{
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
cin>>m[i][j];
}
}
}
void display()
{
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
cout<<m[i][j]<<"\t";
}
cout<<"\n";
}
}
friend matrix operator +(matrix,matrix);
};
matrix operator +(matrix m1, matrix m2)
{
matrix m3;
int i,j;
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
m3.m[i][j] = m1.m[i][j] + m2.m[i][j];
}
}
return m3;
}
void main()
{
clrscr();
matrix m1,m2,m3;
cout<<"\nEnter the first matrix : \n";
m1.getdata();
cout<<"\nEnter the second matrix :\n";
m2.getdata();
m3 = m1 + m2;
cout<<"\nMatrix ans is : \n";
m3.display();
getch();
}
OUTPUT
================
Enter the first matrix :
1
2
3
4
5
6
7
8
9
Enter the second matrix :
1
2
3
4
5
6
7
8
9
Matrix ans is :
2 4 6
8 10 12
14 16 18
* * * * * * * * * * * * * *
>> IF YOU LIKE THIS BLOG, PLEASE SHARE AND SUBSCRIBE. ALSO COMMENT FOR THIS BLOG.
>> IF YOU HAVE ANY QUESTIONS PLEASE ASK IN COMMENT.>> IF YOU WANT TO LEARN HTML WITH OUTPUT, SO VISIT THIS BLOG
https://dnpwebdeveloper.blogspot.com/>> IF YOU WANT TO LEARN C++ PROGRAM WITH OUTPUT, SO VISIT THIS BLOGhttps://cplusplusdnpdeveloper.blogspot.com/
>> IF YOU WANT TO LEARN C PROGRAM WITH OUTPUT, SO VISIT THIS BLOG
Comments
Post a Comment