2.1 Task 1 The purpose of this practical is to examine more complex types of operator overloading in the context of two class

• matrix(file:string): The default constructor. It receives the name of a file that it must then read to construct a matrix.

A=A-B 1,1 1,1 where A and B are both matrices. If the two matrices are of different sizes, then nothing happens and A should

2.1 Task 1 The purpose of this practical is to examine more complex types of operator overloading in the context of two classes. 2.1.1 Matrix The matrix class consists of two files: matrix.h and matrix.cpp. The class has the following definition: matrix -size:int -mat.int** +matrix (file: string) + matrix +operator+(add: matrix*):matrix & +operator-(sub:matrix*) :matrix & +friend operator• matrix(file:string): The default constructor. It receives the name of a file that it must then read to construct a matrix. The first line of the file contains the size of the matrix. The remainder of the file contains the matrix, in a row/column format. Each line will have a number of elements with no delimiters. Each value will be between 0 and 9. • matrix(): The destructor for the class. It deallocates the memory of the class. It will also print out the following message with a new line at the end: matrix sum: X where X is the sum of all of the elements in the matrix. • operator+(add:matrix*): An overload of the + operator. It will be used in conjunc- tion with other matrices in the following way: A=A+B w 3,4 A=A+B 3,5 7,9 where A and B are both matrices. If the two matrices are of different sizes, then nothing happens and A should remain unchanged. If the matrices are same size, then there should be an element-wise addition and the result should be stored in A. This operation should be chainable, so the operator can be used in conjunction with others or itself. • operator-(sub:matrix*): An overload of the operator. It will be used in conjunction with other matrices in the following way: A=A-B по 2 A=A-B 1,1 1,1 where A and B are both matrices. If the two matrices are of different sizes, then nothing happens and A should remain unchanged. If the matrices are same size, then there should be an element-wise subtraction and the result should be stored in A. This operation should be chainable, so the operator can be used in conjunction with others or itself. • friend operator



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *