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];



                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++)







                 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










                 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;



                  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





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
Should I call a destructor explicitly on a local variable?

What is the real function of class - to export data? No, Real purpose of a class isn't to export data. Instead, it's to provide services. Class provides a way to abstract behav

The program will ask the user to enter: '1' to List the cities(and their state abbrev)  from largest to smallest (by their population) with their population '2'  to List the

The Scope Resolution Operator( :: ) Global variables are explained outside any functions and thus can be used by all the functions defined thereafter. However, if a global vari

A r r a y s w i t h i n a c l a s s: I t i s j u s t d ecl a r i n g o r c on s t ru c ti n g a d e r i v e d t

Question A bank normally updates it's clients accounts at the end of each month.Of the two types of bank accounts:savings and checking, a client must maintain a minimum balance

Description A long time ago in a galaxy far, far away, the country Mafghanistan had n cities and m old roads, where each road connected a pair of cities. Due to the treacherous mo

Ques.Implement a c/c++ program to find a shortest path between two nodes in a network?network should be taken as an adjacency matrix.

Implement (a part of) electronic election Scenario where following political parties are participating in election: PPP, PML and PTI.  Create a class PollingStation where it stor