Wed Jan 23, 2013 4:48 pm
// Matrix.cpp: implementation of the Matrix class.
//
//////////////////////////////////////////////////////////////////////
#include<iostream.h>
#include "Matrix.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Matrix::Matrix()
{
C[0][0]=0;
}
Matrix::~Matrix()
{
}
void Matrix::Multplay_Two_Matrixes(float newA[70][70],float newB[70][70])
{
cout<<"The matrix A is: "<<endl;
for(int i=0;i<Arow;i++)
{
cout<<'|';
for(int j=0;j<Acol;j++)
{
A[i][j]=newA[i][j];
cout<<" "<<A[i][j]<<" ";
}
cout<<'|'<<endl;
}
cout<<"The matrix B is: "<<endl;
for(i=0;i<Brow;i++)
{
cout<<'|';
for(int j=0;j<Bcol;j++)
{
B[i][j]=newB[i][j];
cout<<" "<<B[i][j]<<" ";
}
cout<<'|'<<endl;
}
for(i=0;i<Arow;i++)
for(int j=0;j<Bcol;j++)
C[i][j]=0;
int u=Bcol;
for(i=0;i<Arow;i++)
{
for(int j=0;j<Bcol;j++)
{
for(int k=0;k<Brow;k++)
{
C[i][j]+=A[i][k]*B[k][j];
}
}
}
}
void Matrix::NumberOfcolumes(const int newcol)
{
}
void Matrix::NumerOfrows(const int newRowA,const int newRowB,const int newColA,const int newColB)
{
Arow=newRowA;
Brow=newRowB;
Acol=newColA;
Bcol=newColB;
}
void Matrix::DisplayProduct()
{
cout<<"************************************************"<<endl;
for(int i=0;i<Arow;i++)
{
cout<<'|';
for(int j=0;j<Bcol;j++)
std::cin>>j;
cout<<" "<<C[i][j]<<" ";
cout<<'|'<<endl;
}
cout<<"************************************************"<<endl;
}
// Matrix.h: interface for the Matrix class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MATRIX_H__22076ABE_3D9F_4A9C_BCA5_DB7DBCA43C17__INCLUDED_)
#define AFX_MATRIX_H__22076ABE_3D9F_4A9C_BCA5_DB7DBCA43C17__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class Matrix
{
float A[70][70],B[70][70],C[70][70];
int Arow,Brow,Acol,Bcol;
public:
Matrix();
virtual ~Matrix();
void NumerOfrows(const int,const int,const int,const int);
void NumberOfcolumes(const int);
void Multplay_Two_Matrixes(float[][70],float[][70]);
void DisplayProduct();
};
#endif // !defined(AFX_MATRIX_H__22076ABE_3D9F_4A9C_BCA5_DB7DBCA43C17__INCLUDED_)
#include<iostream.h>
#include"Matrix.h"
void main()
{
int Arow,Brow,Acol,Bcol;
Matrix M;
cout<<"Enter the number of row of matrix A : ";
cin>>Arow;
cout<<"Enter the number of col of matrix A : ";
cin>>Acol;
cout<<"Enter the number of row of matrix B : ";
cin>>Brow;
cout<<"Enter the number of row of matrix B : ";
cin>>Bcol;
while(Acol!=Brow)
{
cout<<"Number of columes of matrix A must equal number of rows of matrix "<<endl;
cout<<"Enter the number of col of matrix A : ";
cin>>Acol;
cout<<"Enter the number of row of matrix B : ";
cin>>Brow;
}
M.NumerOfrows(Arow,Brow,Acol,Bcol);
M.NumberOfcolumes(Acol);
float A[70][70];
float B[70][70];
for(int i=0;i<Arow;i++)
for(int j=0;j<Acol;j++)
cin>>A[i][j];
for(i=0;i<Brow;i++)
for(int j=0;j<Bcol;j++)
cin>>B[i][j];
M.Multplay_Two_Matrixes(A,B);
M.DisplayProduct();
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.