Classes define new types in C++. Types in C++ not only interact by means of constructions and assignments but also via operators. For example: int a=2, b=1, c; c = b + a; The result of variable c will be 3. Similarly, classes can also perform operations using operator overloading. Operators are overloaded by means of operator functions, which are regular functions with special names. Their name begins with the operator keyword
Classes define new types in C++. Types in C++ not only interact by means of constructions and assignments but also via operators. For example:
int a=2, b=1, c; c = b + a;The result of variable c will be 3.
Similarly, classes can also perform operations using operator overloading. Operators are overloaded by means of operator functions, which are regular functions with special names. Their name begins with the operator keyword followed by the operator sign that is overloaded. The syntax is:
You are given a main() function which takes a set of inputs to create two matrices and prints the result of their addition. You need to write the class Matrix which has a member a of type
Input Format
First line will contain the number of test cases . For each test case, there are three lines of input.
The first line of each test case will contain two integers and which denote the number of the rows and columns respectively of the two matrices that will follow on the next two lines. These next two lines will each contain elements describing the two matrices in row-wise format i.e. first elements belong to the first row,next elements belong to the second row and so on.
Constraints
, where is the element in the row and column of the matrix.
Output Format
The code provided in the editor will use your class and overloaded operator function to add the two matrices and give the output.
Sample Input
Sample Output
Explanation
The sum of first matrix and the second matrix is the matrix given in the output
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)