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

Assignment Help:

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

                  }


Related Discussions:- C program to show overloading of matrix operator

Add words in dictionary - c++ program, Add words in Dictionary: void D...

Add words in Dictionary: void Dictionary::add( Object& objectToAdd ) {     if( !objectToAdd.isAssociation() )         ClassLib_error( __ENOTASSOC );     else

Skilled programmer is required to build a standalone module, A skilled prog...

A skilled programmer is required to build a standalone module to extract, parse and store in database tables, word count data from web pages and RSS feeds. The module can take R

Describe how a structure differs from a union, Question : (a) How does...

Question : (a) How does a structure differ from an array? (b) Describe how a structure differs from a union? (c) Declare a union called ‘clothes' which consists of the

File Input and Output, Given a bool variable isReadable write some statem...

Given a bool variable isReadable write some statements that assign true to isReadable if the file "topsecret" exists and can be read by the program and assigns false to isR

Nested if else, input marks of c and c++ if c grater than equal to 50 grate...

input marks of c and c++ if c grater than equal to 50 grater than 50 you are pass if c greater than equal to 50 c++ less than 50 than supplementry c++ if c less then 50 and c++ gra

Matrix transposition cipher, write a C rpogram that can display the transpo...

write a C rpogram that can display the transpose form of a ciphertext matrix.Prompt users to provide row and coloumn number of matrix.Then user will input plaintext and the program

Area under the curve, Write a program to find the area under the curve y ...

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. The area under a curve between two points can b

Chelo, need some help with finishing a program

need some help with finishing a program

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