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

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

                  }

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







Related Discussions:- Operator overloading - c++ program, Assignment Help, Ask Question on Operator overloading - c++ program, Get Answer, Expert's Help, Operator overloading - c++ program Discussions

Write discussion on Operator overloading - c++ program
Your posts are moderated
Related Questions
Create a class  called  ticketSelling that stores booking information of a single performance on a single day and sells the tickets of the performance. The class should include at

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules. a. A call made between 8:00 AM and

Object Oriented Programming Paradigm: For OOP, Paradigm is a standard set.  The OOP will help to develop software in modules, which will be integrated later as a full packag

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Write a program to define a matrix: 1. Write a function that takes an integer and calculates and returns the factorial of the integer. The Factorial of a number "n" is compute

Hello, I would like to know if you can help in C programs that work on android.

I need a project on car rental system using c programming only of college level

I am having trouble declaring a variable and returning a value from my function.

to design a car that travels along the room and gives the length of the room

i didnt no how to write and how to implement and the programming can be done in C and execution should be done in UNIX