Question: You have to implement all given requirements in c++ programming language. Question 2 Write a specialized template class for char* datatype. The matrix in such

You have to implement all given requirements in c++ programming language. Question 2

  1. Write a specialized template class for char* datatype. The matrix in such a case will be like a 3-dimensional character array. Memory for each element in the matrix will be allocated dynamically.
  1. For + operator, simple append the corresponding elements of the 2nd matrix passed as parameter with the corresponding elements of the 1st matrix.

For example: Suppose there are two matrices:

matrix1

Computer Electrical

Business Civil

matrix2

Science Engineering

Administration Engineering

Result after applying + operator:

ComputerScience ElectricalEngineering

BusinessAdministration CivilEngineering

  1. The memory (number of bytes) taken by an element in the matrix will not exceed the number of characters in that element. For example the number of characters in Computer is 8, so 8 bytes will be allocated in memory. [As a result, the size of third dimension will be variable]. Also, there must not be any memory leaks.

  1. Implement all the functions/operators for the specialized class template that you have implemented for the original class template in question 1. You will have to allocate dynamic memory for each element in the matrix and also fulfill the requirements stated in point 2.

  1. Also implement an overloaded assignment operator in this specialized class template. Matrix operator=(Matrix const& obj).
  1. Now test your code by running the following instruction in your main function:

Matrix mA(2,2);

mA.insertElement( (char*)"Computer", 0, 0);

mA.insertElement((char*)"Electrical", 0, 1);

mA.insertElement((char*)"Business", 1, 0);

mA.insertElement((char*)"Civil", 1, 1);

mA.print();

Matrix mB(2, 2);

mB.insertElement((char*)"Science", 0, 0);

mB.insertElement((char*)"Engineering", 0, 1);

mB.insertElement((char*)"Administration", 1, 0);

mB.insertElement((char*)"Engineering", 1, 1);

Matrix mC(1, 1);

mC = mA + mB;

mC.transpose();

mC.print();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!