Question
This program is done and solved, but it needs a few requirements to be finished. Thats what I really need help with. Here is the
This program is done and solved, but it needs a few requirements to be finished. Thats what I really need help with.
Here is the question:
Design a class to perform various matrix operations. A matrix is a set of numbers arranged in rows and columns. Therefore, every element of a matrix has a row position and a column position. If A is a matrix of five rows and six columns, we say that matrix A is of the size 5 X 6 and sometimes denote it as A5X6. Clearly, a convenient place to store a matrix is in a two-dimensional array. Two matrices can be added and subtracted if they have the same size. Suppose that A = [aij] and B =[bij] are two matrices of the size m X n, in which aij denotes the element of A in the ith row and the jth column, and so on. The sum and difference of A and B is given by:
A + B = [aij + bij]
A - B = [aij - bij]
The multiplication of A and B (A * B) is defined only if the number of columns of A are the same as the number of rows of B. If A is of the size m X n and B is of the size n X t, then A * B = [cik] is of the size m X t and the element cik is given by the formula:
cik = ai1b1k +ai2b2k + . . . + ainbnk
Design and implement a class matrixType that can store a matrix of any size. Overload the operators +, -, and * to perform the addition, subtraction, and multiplication operations, respectively, and overload the operator
Poster notes: I will post my program below. The program works, but due to the added requirements it is incomplete. the extra requirement is First: "You will have to overload the +, - and * operations. You will also have to overload the >> and Second and most importantly: Your class must have private attributes such as: int **matrix; and variables for the number of rows and number of columns.
I think most of the requirements is done for the First requirement except for the >> operator. if its missing please add it, I would appreciate it. The one I really need help with is the Second requirement. If you manage to fix that then all is well, and I would really be thankful. You don't need to change much of the program and the output should still look the same to the output of the program i will also post below. but since the First requirement added the >> operator, its alright to look a bit different.
IMPORTANT NOTE: The program needs user input(this was already done) and the program must run and compile. Please before posting your solution, make sure the program runs and compile and not cause errors. I just don't wish to waste my question again. I would truly appreciate your help for this. (P.S. I would also post the sample output of the original program I have posted below just for reference)
My Program:
#include
public: matrix() { } matrix(int,int); //member function friend ostream& operator
void getmatrix(); matrix operator+ (const matrix& m); matrix operator- (const matrix& m); matrix operator* (const matrix& s); };
//get matrix member function void matrix::getmatrix() { cout
cin>>a[i][j]; }
//constructor matrix::matrix(int a, int b) { row = a; col = b; }
//overloading operator + matrix matrix::operator+(const matrix& m) { matrix c (row,col); if((row == m.row)&&(col == m.col)) { for(int i=0; i //overloading operator - matrix matrix::operator-(const matrix& m) { matrix c(row,col); if((row == m.row) && (col == m.col)) { for(int i=0; i //overloading operator * matrix matrix::operator*(const matrix& m) { matrix c(row,col); if (col == m.row) { for(int i=0; i //overloading ostream operator ostream& operator //main method int main() { int r,p,x,y,c;// variable //display menu cout Addition" Subtraction" Multiplication" Exit" //inputting choice cout > c; //inputting number of rows columns for matrix1 cout > r >> p; //inputting number of rows columns for matrix2 cout > x >> y; //function calls matrix d(r,p); matrix e(x,y); matrix f(r,p); matrix s(r,p); matrix m(r,y); switch(c) { case 1: //input 2 matrix d.getmatrix(); e.getmatrix(); //operator overloading f = d+e; cout case 2: //input 2 matrix d.getmatrix(); e.getmatrix(); //operator overloading s = d-e; cout case 3: //input 2 matrix d.getmatrix(); e.getmatrix(); //operator overloading m = d*e; cout default: cout return 0; } ----------------------------------------------------------------------------------------------------------------------------------------- Sample output pic:
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