Question
Answer must be in C++. No global variables. No continue statement. Need help writing a 2x2 and 3x3 matrix calculator that also solves the determinant.
Answer must be in C++. No global variables. No continue statement. Need help writing a 2x2 and 3x3 matrix calculator that also solves the determinant.
The program should ask the user what size matrix they want then it must dynamically allocate memory for a 2d array to create matrix then determine the determinant.
Files:
For simplicity, there are only 2 sizes of matrix for this program: either a 2x2 or a 3x3 matrix.
Create a matrix calculator program that consists of 5 files.
The program should have two functions:
void readMatrix()
int determinant()
Each function should have its own header files (.hpp) and source code (.cpp). Including the main file that contains main function to run the program, there should be 5 files for the program to be compiled and run properly.
main function:
The main function should contain following steps:
Ask the users to choose the size of the matrix (2x2 or 3x3).
Dynamically allocates the memory space for the matrix using readMatrix() to prompt the user to enter 4 or 9 integers to fill the matrix
Calculate the determinant using determinant().
Display both the matrix and the determinant to the user.
Note: please display the matrix in a square format, do not display it in a line.
Free the dynamically allocated memory
void readMatrix():
The readMatrix() function has two parameters:
A pointer to a 2D array
An integer as the size of the matrix
The function should prompt the user for all the numbers within the matrix, that means for 2x2 matrix, it should ask the user for 4 numbers, and 9 numbers for a 3x3 matrix. Because the function takes a pointer to the 2D array, it should not return anything.
int determinant():
The determinant() function has two parameters:
A pointer to a 2D array
An integer as the size of the matrix
The function takes in the 2D array, which contains the value inside the matrix, and calculate the determinant. Afterwards, the function should return the determinant.
Also
The program needs to dynamically allocate the 2D array in main function, and free the dynamically allocated memory when it is no longer in use.
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