| | |
Assistace please
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 6
Reputation:
Solved Threads: 0
I need to Construct a program that inputs the entries of two matrices and multiplies them. Construct the program so that it gives an error message if they cannot be multiplied.
What I have done so far
I need to Construct a program that inputs the entries of two matrices and multiplies them. Construct the program so that it gives an error message if they cannot be multiplied.
What I have done so far
What I have done so far
I need to Construct a program that inputs the entries of two matrices and multiplies them. Construct the program so that it gives an error message if they cannot be multiplied.
What I have done so far
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <vector> using namespace std; class MatrixNxN { public: int numRows; int numCols; float index[4][4]; }; void printMatrix(MatrixNxN a); MatrixNxN inputMatrix(); //This function returns true if the matrices are compatible for multiplication. bool canMultiplyMatrices( MatrixNxN a, MatrixNxN b ); //This function actually multiplies the matrices together. MatrixNxN multiplyMatrices(MatrixNxN a, MatrixNxN b); void main() { cout << "Please enter matrix A:" << endl; MatrixNxN A = inputMatrix(); printMatrix( A ); cout << " Please enter matrix B:" << endl; MatrixNxN B = inputMatrix(); printMatrix (B); //I need help checking to see if I can multiply the two matrices. // If not, say so and return. //I need help multiplying the matrices to get a result. //I need help printing the result. } MatrixNxN inputMatrix() { MatrixNxN temp; //loop through rows int rows = 0, cols = 0; while( rows <= 0 || rows > 4 ) { cout << "Please enter a row count between 1 and 4: "; cin >> rows; } while( cols <= 0 || cols > 4 ) { cout << "Please enter a column count between 1 and 4: "; cin >> cols; } temp.numRows = rows; temp.numCols = cols; for(int i = 0; i < rows; ++i) { //loop through column at each row for(int j = 0; j < cols; ++j) { //i is the row & j is the column cout << "Enter row " << i << " column " << j << ": " << endl; cin >> temp.index[i][j]; } } return temp; } void printMatrix(MatrixNxN a) { for(int i = 0; i < a.numRows; ++i) { //loop through column at each row for(int j = 0; j < a.numCols; ++j) { //i is the row & j is the column cout << "row " << i << " column " << j << ":" << a.index[i][j] << endl; } } } bool canMultiplyMatrices( MatrixNxN a, MatrixNxN b ) { //What do I do here to find out if the matrices are compatible for multiplication? return false; } MatrixNxN multiplyMatrices(MatrixNxN a, MatrixNxN b) { MatrixNxN temp; //I need help filling in the entries of temp. Don't forget to set its numRows and numCols fields! //I need to use a loops to multiply these matrices. Follow what the other functions are doing //and I'll need a third loop in the middle to add up the terms for each entry in the result. return temp; }
To test whether the matrices are compatible for multiplication, you have to check that the second dimension of the first matrix ( y1 ) is equal to the first dimension of the second matrix ( x1 ).
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
•
•
•
•
I need to Construct a program that inputs the entries of two matrices and multiplies them. Construct the program so that it gives an error message if they cannot be multiplied.
What I have done so far
I need to Construct a program that inputs the entries of two matrices and multiplies them. Construct the program so that it gives an error message if they cannot be multiplied.
What I have done so far
And your question is?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Other Threads in the C++ Forum
- Previous Thread: is this matrix code working?
- Next Thread: Softwares developed with C++
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






