/*write a c++ program to consider the class matrix
class matrix
{
int a[3][3];
public:\\method;
};
overload the -(unary) should negate the number stored in the object.
*/
#include<iostream.h>
#include<conio.h>
class matrix
{
int a[3][3];
public: void accept();
void display();
void operator -();
};
void matrix::accept()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
}
void matrix::display()
{
int i,j;
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<"\t"<<a[i][j];
}
}
cout<<"\n";
}
void matrix ::operator -()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=-a[i][j];
}
}
}
int main()
{
clrscr();
matrix m;
cout<<"Enter the matrix :";
m.accept();
-m;
cout<<"\narray after negation is\n";
m.display();
getch();
return 0;
}
/*
Enter the matrix :
1 2 3
7 4 1
9 6 3
array after negation is
-1 -2 -3
-7 -4 -1
-9 -6 -3
*/
class matrix
{
int a[3][3];
public:\\method;
};
overload the -(unary) should negate the number stored in the object.
*/
#include<iostream.h>
#include<conio.h>
class matrix
{
int a[3][3];
public: void accept();
void display();
void operator -();
};
void matrix::accept()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
}
void matrix::display()
{
int i,j;
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<"\t"<<a[i][j];
}
}
cout<<"\n";
}
void matrix ::operator -()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=-a[i][j];
}
}
}
int main()
{
clrscr();
matrix m;
cout<<"Enter the matrix :";
m.accept();
-m;
cout<<"\narray after negation is\n";
m.display();
getch();
return 0;
}
/*
Enter the matrix :
1 2 3
7 4 1
9 6 3
array after negation is
-1 -2 -3
-7 -4 -1
-9 -6 -3
*/
No comments:
Post a Comment