Question
Write a c++ program on templates: You are going to implement a class richMatrix which is going to demonstrate the use of templates. This class
Write a c++ program on templates:
You are going to implement a class richMatrix which is going to demonstrate the use
of templates. This class is going to implement a number of methods that all make use
of templates in order to make the class very exible. In this case, the usage of < T >
indicates a template class with the specic usage of T as the indicator for the template
type.
The class is described according to the simple UML diagram below:
richMatrix
------------------------
+createNewMatrix(size:int): T **
+addMatrix(mat1: T**,mat2:T**,size:int): T**
+subtractMatrix(mat1:T**,mat2:T**, size:int):T**
+transposeMatrix(mat1:T**, size:int):T**
+print(mat:T**,size:int):void
The class methods do the following:
createNewMatrix: This receives a size and makes a new square matrix of type T
that is returned. The matrix is not populated with anything at this point.
addMatrix: This function receives two square matrices, with their size dened by the
the passed in size argument. This method will do an element-wise addition between
both matrices and return a third matrix containing the results of this operation. In
the case of strings, this will concatenate the two elements together.
transposeMatrix: This function receives a matrix, and a size, and then produces a
transpose of the given matrix. Importantly, the matrix returned is the original one
with the transposition performed, and not a new matrix.
subMatrix: This function receives two square matrices, with their size dened by
the the passed in size argument. This method will do an element-wise subtraction,
mat1-mat2, between both matrices and return a third matrix containing the results
of this operation.
print: This method will receive a square matrix whose size is an argument passed
in. It will then print this matrix out line by line, with all the elements of one row
on one line, with no delimiters.
You will be allowed to use the following libraries: cstdlib,string,iostream.
Your submission must contain richMatrix.h,
richMatrix.cpp, main.cpp
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started