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

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

                  }

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







Related Discussions:- C program to show overloading of matrix operator, Assignment Help, Ask Question on C program to show overloading of matrix operator, Get Answer, Expert's Help, C program to show overloading of matrix operator Discussions

Write discussion on C program to show overloading of matrix operator
Your posts are moderated
Related Questions
Create a pseudocode in getting Calendar Quarter. The program should identify which quarter falls the given date. Note: Consider the date format DDMMYYYY.

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

Explain procedural logic A procedure, or function, was explained as a set of specific instructions implemented in sequential manner. The data is kept separate from the procedur

how can i easily make a program?

.Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

padovan string for a natural number is defined

can you tell me what is c#

What are the benefits of using friend classes? - Friend classes are useful when a class wants to hide features from users which are required only by another, tightly coupled cl

Write the statements which are used to connect PHP with MySQL? Statements which can be used to connect PHP with MySQL is: $conn = mysql_connect('localhost'); echo $co

I need plugin for amibroker using c++ Project Description: Need to prepare plugin for amibroker using c++. Should be system bound after installing. System should show based o