Sunday, July 13, 2008
Structural Programming Lab7 5b?
My code on 2X2 matrix.
iostream and iomanip(to look nicer) does not appear, add in yourself.
#include
#include
using namespace std;
int matrix1[2][2], matrix2[2][2], matrix3[2][2];
//function prototypes
int inputfunction1 (int matrix1[2][2]);
int inputfunction2 (int matrix2[2][2]);
int matrixfunction1 (int matrix3[2][2]);
int main()
{
//displaymatrixdiagram ();
cout << "first matrix second matrix third matrix" << endl;
cout << "[0][0] [0][1] [0][0] [0][1] [0][0] [0][1]" << endl;
cout << "[1][0] [1][1] X [1][0] [1][1] = [1][0] [1][1]" << endl;
matrixfunction1 (matrix3);
cout << "first matrix second matrix thrid matrix" << endl;
cout << "[" << setw(3) << matrix1[0][0] << " " << setw(3) << matrix1[0][1] << "] [" << setw(3) << matrix2[0][0] << " " << setw(3) << matrix2[0][1] << "] [" << setw(3) << matrix3[0][0] << " " << setw(3) << matrix3[0][1] << "]" << endl;
cout << "[" << setw(3) << matrix1[1][0] << " " << setw(3) << matrix1[1][1] << "] X [" << setw(3) << matrix2[1][0] << " " << setw(3) << matrix2[1][1] << "] = [" << setw(3) << matrix3[1][0] << " " << setw(3) << matrix3[1][1] << "]" << endl;
return 0;
}
int inputfunction1 (int matrix1[2][2])
{
int r, c;
for (r = 0; r < 2; r++)
{
for (c = 0; c < 2; c++)
{
cout << "Please enter [" << r << "][" << c << "] for first matrice: ";
cin >> matrix1[r][c];
}
}
return(matrix1[2][2]);
}
int inputfunction2 (int matrix2[2][2])
{
int r, c;
for (r = 0; r < 2; r++)
{
for (c = 0; c < 2; c++)
{
cout << "Please enter [" << r << "][" << c << "]for second matrice: ";
cin >> matrix2[r][c];
}
}
return(matrix2[2][2]);
}
int matrixfunction1 (int matrix3[2][2])
{
int r, c;
inputfunction1(matrix1);
inputfunction2(matrix2);
for (r = 0; r < 2; r++)
{
for (c = 0; c < 2; c++)
{
matrix3[r][c] = matrix1[r][0] * matrix2[0][c] + matrix1[r][1] * matrix2[1][c];
//cout << matrix3[r][c] << endl;
}
}
return (matrix3[2][2]);
}
This crap took me 3 hours. Try, you can do it too. =)
; tortured on 10:12 PM =/
__________________________________
the1B02
ONE class of FIFTEEN gentlemen and FIVE ladies
average age of SEVENTEEN
first met each other on 8th apr 08 at T1442
we are
environmental friendly
theCREWS
Designer: no idea
Code Edited: abigail/han sheng
Picture: photobucket
Host: blogger::
photobucket
Thanks: blogskins
click THIS: ♥
thecopyCATS
this blog was created by HANSHENG.
the templater was ABIGAIL.
blogskin found by JESSLE.
you are NOT ALLOWED to copy or take anything from HERE. trespassers WILL be prosecuted.