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

Class, array of class objects and single inheritance

array of class objects and single inheritance

Array, Assigning value to individual elements in array

Assigning value to individual elements in array

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

C++ Assignment Help me , Write a c++ program that contain the following fun...

Write a c++ program that contain the following functions : 1) Function Quality_Point that takes one int argument (student_average) and return ‘A’ if the student_average between 90-

Explain the bit wise operations, Explain the Bit Wise Operations? C lan...

Explain the Bit Wise Operations? C language in particular was created to make it easier to write operating systems. The objective was to have a language that provided excellent

Algorithm, Write a algorithm to explain the processof wakingbup in morning

Write a algorithm to explain the processof wakingbup in morning

Program to compute quadratic polynomial, Write a function that computes f(x...

Write a function that computes f(x) for a quadratic polynomial in x, such as the one in assignment 3. Use the function to plot f(x) from -10 to +10.

Area under curve, Write a program to find the area under the curve y = f(x)...

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. #include float start_point,

Write a program to sort an array of strings, Write a program to sort an arr...

Write a program to sort an array of strings. Use new and delete operators. Write a program to find the factorial of a number using recursion. If we do not accept the number

''c'' programme, Write a ''C'' program to accept any 3 digit integer number...

Write a ''C'' program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

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