Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use 2 dimmensional dynamic array and template class while programming with C++. Question: Write a C++ program that has following Template class: template Matrix

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Please use 2 dimmensional dynamic array and template class while programming with C++.

Question: Write a C++ program that has following Template class: templateMatrix _** matrix1: M_type _**matrix2: M_type -rows: int -cols: int +Matrix(): Default Constructor +Matrix(const int &row, const int &col): Overloaded Constructor +-Matrix(): destructor +printMatrix1(): void +printMatrix2(): void +addMatrix(): void +findElements(): void +operator[](const int &index): M_type*& +getRow(): int +getColl): int +setRow(int) +setCol(int) Class Variables: M_type **matrix1: 2 dimensional dynamic array for first matrix. M_type **matrix2: 2 dimensional dynamic array for second matrix. Int rows: Number of rows for matrices. Int cols: Number of columns for matrices. Class Functions: Matrix(): This is default constructor of Matrix class. Matrix(int row, int col): Overloaded constructor of Matrix class. It takes integer row and column values as parameters. -Matrix(): This is destructor class that should free memory by deleting dynamic arrays of Matrix class. void findElements(M_type value): This function let user find any element in both matrices. Function takes M_type value as a parameter and finds the element in the matrices. Then, prints the index numbers for each occurrence and total frequency that are found in both matrices. void addMatrix(): This functions simply adds two matrices of Matrix class. Then, prints the added matrix to the screen. void inputMatrix1(): In this function, you should get inputs from the user for elements of first matrix. void inputMatrix2(): In this function, you should get inputs from the user for elements of second matrix. int getRow(): This function returns number of rows for the matrices. int getCol(): This function returns number of columns for the matrices. void setRow(int row): This function changes number of rows for the matrices. void setCol(int col): This function changes number of columns for the matrices. void printMatrix10): This function prints the elements of first matrix. void printMatrix2(): This function prints the elements of second matrix. M_type*& operator[](const int &index): This is an overloaded operator for 1)" operator. It should return the value according to the given indices. You should use Assert() function to check that index>=0 and index

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

Students also viewed these Databases questions