0

Is this code compiling

#include <iostream>
usingnamespace std;
//Define the Matrix3X3 type.
typedefstruct
{
float index[3][3];
} Matrix3X3;
//Function prototypes (functions are defined below main())
void printMatrix( Matrix3X3 a );
Matrix3X3 inputMatrix();
Matrix3X3 addMatrices( Matrix3X3 a, Matrix3X3 b );
Matrix3X3 subtractMatrices( Matrix3X3 a, Matrix3X3 b );
Matrix3X3 scalarMultiply( Matrix3X3 a, float scale );
 
//main() function
 
 
void main()
{
cout << "Please enter matrix A:" << endl;
Matrix3X3 A = inputMatrix();
cout << "Matrix A:" << endl;
printMatrix( A );
cout << "Please enter matrix B:" << endl;
Matrix3X3 B = inputMatrix () ;
cout << "Matrix B:" <<endl;
printMatrix ( B );
printMatrix(scalarMultiply(A, 3.1415)); 
} 
 
Matrix3X3 scalarMultiply( Matrix3X3 a, float scale ) 
{ 
Matrix3X3 result; 
for(int i=0;i<3; i++) 
for(int j=0;j<3; j++) 
result.index[j][i] = scale * a.index[j][i]; 
return result;
}
Matrix3X3 subtractMatrices( Matrix3X3 a, Matrix3X3 b ) 
{ 
Matrix3X3 result; 
for(int i=0;i<3; i++) 
for(int j=0;j<3; j++) 
result.index[j][i] =a.index[j][i] - b.index[j][i]; 
return result;
} 
 
void printMatrix( Matrix3X3 a )
{
//loop through rows
for( int i=0; i < 3; ++i )
{
//loop through column at each row
for( int j=0; j < 3; ++j )
{
//i is the row
//j is the column
float temp = a.index[i][j];
cout << temp << " ";
}
//go to the next line after each row
cout << endl;
}
}
Matrix3X3 inputMatrix()
{
Matrix3X3 temp;
//loop through rows
for( int i=0; i < 3; ++i )
{
//loop through column at each row
for( int j=0; j < 3; ++j )
{
//i is the row
//j is the column
cout << "Enter row " << i << " column " << j << ":" << endl;
cin >> temp.index[i][j];
}
}
 
return temp;
}
3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Nick Evan
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.