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
Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Presently we are using several spreadsheets to give weekly activity and income reports. Much of the information is being frequently re-keyed into several spreadsheets - we are look

#question:-program to counts tha no of occurances of the string in the nth padovan string

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

The zipped folder int_collection.zip (downloaded from Blackboard) contains an abstract class AbstractIntCollection and two interfaces: IntList and IntStack. The abstract class cont

wap to cheak if a number is palindrom

algorithm to find whether a given number is prime number or not? using pseudo code and flowchart

Step 1 Define the start of the program    It should be noted that within C all commands should end in a semi-colon. For most of your programs the definition of a program header as

Implement, in rPeANUt, the a Fibonacci function by using the simple recursive approach. The Fibonacci function can be implemented in c as follow: int fib(int x) {   if (x

Compiler Design - Limit In The Method Instructions