ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

To use structure and pointers to implement dynamic data structure

by | Nov 29, 2023 | questions

Write a program to read in two floating point matrices A and B, which are of dimensions specified by the
user. Dynamically allocate space for both input matrices.
Implement 4 matrix operators: add, subtract, multiply and inverse, each of which should be implemented
as a function using call by reference. Devise appropriate tests within each function to determine whether
the operator is valid for the dimensions specified – if not, an error should be printed.
Inverse should only be implemented for 2×2 matrices only and only for the A matrix. Attempting to
compute the inverse of any other size should print an error message.
Full credit will only be given for solutions that follow the specification, but also where each part of the
program has been thoroughly tested, both with valid and invalid data. Use appropriate error messages
whenever the user enters invalid data.
Hint: You need to devise a suitable structure to store the dimensions and the data of each matrix. The
function call, for example, to multiply A and B together should be as simple as
multiply_matrix(A, B)
where A and B are structures (or pointers to structures). You may choose simply to print out the result on
the screen, or store the result in a matrix C with a separate print_matrix function, e.g.

the screen, or store the result in a matrix C with a separate print_matrix function, e.g.
NOTE -the example is shown in the attached file

Sample output of program:
1 – Enter matrices A & B
2 – Add matrices
3 – Subtract matrices
4 – Multiply matrices
5 – Inverse of A
6 – Quit program

Option: 1
Number of rows in A: 2
Number of columns in A: 3
Enter matrix data:
1 2 3
3 4 5

Number of rows in B: 2
Number of columns in B: 3
Enter matrix data:
4 3 2
2 1 0
(menu is printed out again)

Option: 2
A + B =
5.0 5.0 5.0
5.0 5.0 5.0

Option: 3
A – B =
-3.0 -1.0 1.0
1.0 3.0 5.0

Option: 4
Inverse of A is invalid for a 2×3 matrix

Option: 1
Number of rows in A: 2
Number of columns in A: 2
Enter matrix data:
2.0 1.0
1.0 2.0

Number of rows in B: 2
Number of columns in B: 2
Enter matrix data:
0.5 0.0
0.0 0.5

Option: 4
A * B =
1.0 0.5
0.5 1.0

Option: 5
Inverse of A =
0.66667 -0.33333
-0.33333 0.66667

Special note:
If you enter option 1 to enter A and B, and then you enter 1 again later in the program to enter new A and B matrices, the entry routine should free the previously allocated space (in order to avoid memory leaks)

Attachments:


ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!