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

Arrays, how to write a program using arrays

how to write a program using arrays

Recursive function, Binomial coefficients are the numeric factors of the pr...

Binomial coefficients are the numeric factors of the products in a power of a binomial such as (x + y)n. For example, (x + y)2 = x2 + 2 x y + y2 has the coefficients 1 2 1. Binomia

Implement the c++ code in assembly language, Selecting Array Elements Imple...

Selecting Array Elements Implement the following C++ code in assembly language, using the block-structured .IF and .WHILE directives. Assume that all variables are 32-bit signed in

#compiler design limiting instrutions, Ravi is a newbie to the programming ...

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules: · Each program must start with ''''''''{'''''''' and end wi

Need payment gateway integration expert, Need Payment Gateway Integration E...

Need Payment Gateway Integration Expert Project Description: I am seeking for expert payment gateway integration. You must have done or have experience with integrating me

Coding Arena A B C D E F G, Damjibhai and Sham...

Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed

Car rental system, complex coding with structure and file handling

complex coding with structure and file handling

C++ age guessing game, Write a program that predicts users’ age (0-128 year...

Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

Explain the parts of operators, Explain the parts of operators Assignm...

Explain the parts of operators Assignment Operators The equal (=) sign is used for assigning a value to another. The left hand side has to be a variable (lvalue, which exc

Substitution model, (a) Write a procedure called (mult x y) that multiplies...

(a) Write a procedure called (mult x y) that multiplies two numbers x and y in a recursive manner using successive addition. Specifically, note that a x b = a + a + .... + a (b tim

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