C program to show overloading of matrix operator, C/C++ Programming

Assignment Help:

C program to show overloading of matrix operator:

Write a program for matrix operator overloading.

class matrix{

 

                private :

                int x[2][2];

 

                public:

                void show();

 

                matrix operator + (matrix);

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

 

                matrix() //default constructor

                {

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

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

                x[i][j]=0;

                }

       ~matrix()

       {

       }

       };

                 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;

                                   }

 

 

                 matrix   matrix :: operator +(matrix b)

                    {

                    matrix c;

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

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

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

                     return c;

                     }

 

       void main()

                 {

                  matrix a,b,c;

                  clrscr();

                  b=a=matrix(1,2,3,4);

                  c=a+b; //c=a.operator + (b);

                                 //here b is the argument passed to the memeber function

                                 //where a is the invoking object of the operator + function

                                 //whereas in friend function a anb b are treated as

                                 //arguments

                  c.show();

                  getch();

                  }


Related Discussions:- C program to show overloading of matrix operator

Last ant on rod, There are ''''n'''' ants on a ''''n+1'''' length rod. The ...

There are ''''n'''' ants on a ''''n+1'''' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are mov

Logic behind object oriented programming, In this we will take a closer loo...

In this we will take a closer look at the logic behind Object Oriented Programming.  Read through the pseudocode listed below and answer the following questions. Class Square

Program, program to check whether a given point lies inside a rectangle or ...

program to check whether a given point lies inside a rectangle or not

C program for removing char which u want, C Program for REMOVING CHAR WHICH...

C Program for REMOVING CHAR WHICH U WANT void main() {           int i,j;           char a[100],r;           clrscr();           for(i=0;i

Eevrv, Ask question #Mi fd d fffffffffffffffffffffffffffffffffffffffffff...

Ask question #Mi fd d fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

Board coloring, coloring of elements in matrix form inm particular matrix.t...

coloring of elements in matrix form inm particular matrix.the color should not match with another color.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd