Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

=+ c. What happens to investment in Oceania?

Answered: 1 week ago