Operator overloading - c++ program, C/C++ Programming

Operator overloading - c++ program:

Write a program in c to define operator overloading.

class matrix{

 

                private :

                int x[2][2];

 

                public:

                void show();

                matrix(int a,int b,int c,int d);

 

                matrix() //default constructor

                {

                for (int i= 0;i<2;i++)

                for(int j=0;j<2;j++)

                x[i][j]=0;

                }

 

                friend matrix operator + (matrix a,matrix b);

                };

 

                matrix operator +(matrix a,matrix b) //optr over loading +

                {

                matrix c;

                for (int i= 0;i<2;i++)

                                for(int j=0;j<2;j++)

                                                c.x[i][j]=a.x[i][j] + b.x[i][j];

 

                 return c;

                 }

                 matrix operator -(matrix a,matrix b) //optr over loading +

                {

                matrix c;

                for (int i= 0;i<2;i++)

                                for(int j=0;j<2;j++)

                                                c.x[i][j]=a.x[i][j] - b.x[i][j];

 

                 return c;

                 }

 

                 void matrix ::show()

                 {

                 for (int i= 0;i<2;i++)

                                for(int j=0;j<2;j++)

                                                 cout <<"\n"<

 

                  }

                  matrix:: matrix (int a,int b,int c,int d)//constructor definition

                                   {

 

                                                   x[0][0]=a;

                                                   x[0][1]=b;

                                                   x[1][0]=c;

                                                   x[1][1]=d;

                                   }

 

       void main()

                 {

                  matrix a,b(2,2,2,2),c;

                  a=matrix(1,1,1,1);

                  clrscr();

                  c=a+b;

 

                  c.show();

                  c=a-b;

                  c.show();

                  getch();

                  }

Posted Date: 10/19/2012 2:59:19 AM | Location : United States







Related Discussions:- Operator overloading - c++ program, Assignment Help, Ask Question on Operator overloading - c++ program, Get Answer, Expert's Help, Operator overloading - c++ program Discussions

Write discussion on Operator overloading - c++ program
Your posts are moderated
Related Questions
write a c++ program, that finds the minimum total number of shelves, including the initial one, required for this loading process.

Friend for Overloading Operators Sometimes friend functions cannot be avoided. For example with the operator overloading. Consider the following class that have data members to

#C Why don''t online compilers support the header file? What can I do to resolve this? PS. I have tried , does''nt work either. Thannk in advance.

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

How much does it cost to complete a C++ assignment that is 80% finished??

I have an exercise with 2 problems. One that is partially completed except with read problems with memory overwrite, and the other problem. I have enclosed the instructions documen

Tracing of Abstract array: inline int isZero( const Object& o ) {     return o == NOOBJECT; }   int AbstractArray::isEqual( const Object& obj ) const {

HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . ALSO HOW I CAN A BECOME A GOOD PROGRAMMER IN C WHAT I DO FOR GOOD PROGRAMMING ,TELL ME HOW C CODING DEVELOP DY ITSELF

give an example of function

Need FTP Upload and MySQL Project Description: We are in need of an executable application that will be execute as a scheduled task on Windows Server 2008 R2 and can perform