Highlights
Write a program (called matrix. CPP) that does the following:
1. Implement a class called Matrix that:
• Contains private member fields for the number rows and columns of the matrix
• Contains a public member field to contain the matrix elements
This should be a 2D array of integers that is implemented dynamically
• Contains five public functions
add function, that adds two same sized matrices together and returns a new matrix with the result
subtract function, that subtracts two same sized matrices together and returns a new matrix with the result
multiply function, that performs proper matrix multiplication and returns a new matrix with the result
scalar function, that performs scalar multiplication with an integer value and a matrix and returns a new matrix with the result
print function, that outputs the contents of the matrix in tabular form that matches the dimensions of the matrix
• Contains a non-default constructor
Constructor that accepts size information, and dynamically creates the matrix
• Contains a destructor That properly handles discarding the dynamically created 2D array (using the delete and setting the member field to null
Matrix Class
1-.Performs the following calculations and prints each result using the print function
• Each of the four matrix mathematical methods should be called, each result stored in a new object
• If the dimensions of the two matrices involved do not allow for the operation to be performed, skip performing this calculation, and display a message stating that step has been skipped.
For example, if I have a 3x4 matrix and a 4x2 matrix, I cannot add or subtract these together, but I can perform multiplication
• Each calculation should be printed with a full explanation For scalar multiplication, you can either use an integer literal or generate a random integer. Just be sure to print the value of the integer value as part of the output when performing this function.
The calculation is performed should be explained, and the contents of each matrix or value involved should be printed and identified.
2. Matrix Class with Overloaded Operators
Using the class from the first portion of the assignment, write a program (called matrix_ops.CPP) that does the following:
1. Overloads the following operators using friend:
• +
Replicate the functionality of the add function from the matrix.CPP
• –
Replicate the functionality of the subtraction function from the matrix.CPP
• *
Overload this to replicate the functionality of both the matrix multiplication and scalar multiplication functions from the matrix.CPP
This operator should be overloaded a total of 3 times.
• <<
Replicate the functionality of the print function from matrix.cpp
Used in the following way: cout << matrix_instance1;
• >>
Used as the only way to fill in a matrix with values
Used in the following way: cin >> matrix_instance1;
3. Performs the following calculations and prints each result using the overloaded >> operator
• Each of the four matrix mathematical methods should be called, each result stored in a new object. Be sure you invoke scalar multiplication once for each overloaded operator o int * Matrix
Matrix * int
• If the dimensions of the two matrices involved do not allow for the operation to be performed, skip performing this calculation, and display a message stating that step has been skipped.
For example, if I have a 3x4 matrix and a 4x2 matrix, I cannot add or subtract these together, but I can perform multiplication
• Each calculation should be printed with a full explanation
For scalar multiplication, you can either use an integer literal or generate a random integer. Just be sure to print the value of the integer value as part of the output when performing this function.
The calculation is performed should be explained; the contents of each matrix or value involved should be printed and identified.
This CMPSC 122 - Mathematics Assignment has been solved by our Mathematics Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment Experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.