#include<iostream.h>
#include<conio.h>
class Matrix
{
int a[3][3];
public:
void accept()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<endl<<"Enter a value(["<<i+1<<"]["<<j+1<<"]): ";
cin>>a[i][j];
}
}
}
void display()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
}
void operator-()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
a[i][j]=-a[i][j];
}
};//End of class
int main()
{
Matrix m;
clrscr();
cout<<endl<<"Enter Matrix1: ";
m.accept();
cout<<endl<<"Matrix1 is: "<<endl;
m.display();
-m;
cout<<endl<<"Matrix1 after negation: "<<endl;
m.display();
getch();
return 0;
}
Post a Comment