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

Assignment Help:

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();

                  }


Related Discussions:- Operator overloading - c++ program

Vision based simultaneous mapping and localization, Project Description: ...

Project Description: Design and prepare software that can navigate a mobile robot using SLAM technique using vision sensor (camera). Skills required are C Programming, Engine

Define how passing arrays to a function, Define How Passing Arrays to a Fun...

Define How Passing Arrays to a Function? A complete array can be passed to a function as an argument. The manner in which the array is passed be different from that of an ordin

Virtual ATM, #questio A charitable organization wants to design a special A...

#questio A charitable organization wants to design a special ATM machine to be used by needy people. The association supplies the needy person with a pin number to be able to use

#psuedocode, Create a pseudocode in getting Calendar Quarter. The program s...

Create a pseudocode in getting Calendar Quarter. The program should identify which quarter falls the given date. Note: Consider the date format DDMMYYYY.

Padovan string, A Padovan string P(n) for a natural number n is defined as:...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

What is memory allocation, What is memory allocation? Memory Allocation...

What is memory allocation? Memory Allocation : It is the method of allocating memory storage to program in such that the program can be run.

Padovan string, A Padovan string P(n) for a natural number n is defined as:...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concate

Assignmet, I have a assignment deadline is 11.11.2015 can I get help

I have a assignment deadline is 11.11.2015 can I get help

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