28.Consider a class Matrix Class Matrix { int a[3][3]; Public: //methods; }; Overload the – (Unary) should negate the numbers stored in the object.


#include<iostream.h>
#include<conio.h>
class matrix
{
int a[3][3];
public:
void get();
void disp();
void operator-();
};
void matrix::get()
{
cout<<“\nEnter the Matrix element: “;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>a[i][j];
}
}
}
void matrix::disp()
{
cout<<“\n Matrix is: \n”;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<a[i][j]<<“\t”;
}
cout<<“\n”;
}
}
void matrix::operator-()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=-a[i][j];
}
}

}
void main()
{
matrix m;
clrscr();
m.get();
m.disp();
-m;
m.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s