Question: Write a C++ code.(Visual Studio). Question 2 a. Write a specialized template class for char* datatype. The matrix in such a case will be like

Write a C++ code.(Visual Studio). Question 2 a. 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.

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

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.

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.

Also implement an overloaded assignment operator in this specialized class template. Matrix operator=(Matrix const& obj).

b. 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!