Perkalian 2 Matriks valid

21 Jun

#include
#include
#include
#include

class matrix{
friend ostream& operator<>(istream&, matrix&);
public :
void input_matrix();
void perkalian_2matrix(const matrix&, const matrix&);
private:
int M[20][20];
int baris, kolom;
};
void matrix::input_matrix(){
int i,j;
for(i=0;i<baris;i++){
for(j=0;j<kolom;j++){
cout<<"Data ["<<(i+1)<<"] ["<<(j+1)<>M[i][j];
}
}
}
void matrix::perkalian_2matrix(const matrix& matrix1, const matrix& matrix2){
int i,j,k;
int barkol;

baris=matrix1.baris;
kolom=matrix2.kolom;
barkol=matrix1.kolom;
if(matrix1.kolom!=matrix2.baris){
cout<<"Tidak bisa menampilkan"<<endl;
baris=0;
goto loncat;
}

for(i=0;i<baris;i++){
for(j=0;j<kolom;j++){
M[i][j]=0;
for(k=0;k>(istream& in, matrix& input){
cout<>input.baris;
cout<>input.kolom;
cout<<"Masukkan data matrix = ";
input.input_matrix();

return in;
}
ostream& operator<<(ostream& out, matrix& output){
int i,j;
for(i=0; i<output.baris; i++){
for(j=0; j<output.kolom; j++){
cout<<setw(5)<<output.M[i][j]<<" ";
}
cout<<endl;
}
return out;
}
main(){
matrix matrix1, matrix2;
matrix kali;
cout<<"Masukkan Data Matrix ke-1"<>matrix1;
cout<<matrix1;
cout<<"Masukkan Data Matrix ke-2"<>matrix2;
cout<<matrix2;
kali.perkalian_2matrix(matrix1, matrix2);
cout<<"Hasil perkalian dua matrix"<<endl;
cout<<kali;
getch();
return 0;
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: