Anggota kelompok :
1. Adimas fajar S (09018225)
2. Adnan Ilham Rifai (09018196)
3. Nur kahfi Ibrahim (09018238)
4. Bagus Raditya W (09018231)
1. File Header C
#ifndef __matrik |
#define __matrik |
#include <iostream.h> |
class Matrik{ |
public: |
void baca_matrik(); |
void matrik_iden(); |
void determinan_inverse(); |
void matrik_jumlah(const Matrik&, const Matrik&); |
void kurang_matrik(const Matrik&, const Matrik&); |
void perkalian_matrik(const Matrik&, const Matrik&); |
void assign_matrik(const Matrik&, const Matrik&); |
void cetak_matrik(); |
private: |
int A[10][10]; |
int baris, kolom; |
}; |
void Matrik::baca_matrik(){ |
lanjut: |
cout << "Banyak baris : "; |
cin >> baris; |
cout << "Banyak kolom : "; |
cin >> kolom; |
if(baris != kolom){ |
cout << "Maaf baris dan kolom harus sama\n"; |
goto lanjut; |
} |
int i, j; |
for(i=0; i<baris; i++) |
for(j=0; j<kolom; j++){ |
cout << "Data[" << 1+i << "," << 1+j << "]:"; |
cin >> A[i][j]; |
} |
}; |
void Matrik::matrik_iden(){ |
int i, j; |
cout << "baris : "; |
cin >> baris; |
cout << "kolom : "; |
cin >> kolom; |
cout<<endl; |
cout<<"matrik Identitas"<<endl; |
for(i=0; i<baris; i++){ |
for(j=0; j<kolom; j++) |
if(i==j) A[i][j]=1; |
else A[i][j]=0; |
} |
for(i=0; i<baris; i++){ |
for(j=0; j<kolom; j++) |
cout << A[i][j] << "\t"; |
cout << endl; |
} |
} |
void Matrik::determinan_inverse(){ |
if((baris==2)&&(kolom==2)){ |
int det; |
int a, b, c, d; |
det=(A[0][0]*A[1][1])-(A[0][1]*A[1][0]); |
cout << "Determinan : " << det << endl; |
a=A[0][0]*det; |
b=-A[0][1]*det; |
c=-A[1][0]*det; |
d=A[1][1]*det; |
cout<<endl; |
cout << "Inverse Matrik\n"; |
cout << d << "\t" << b << endl; |
cout << c << "\t" << a << endl; |
} |
else cout << "Maaf saat ini hanya matrik 2x2" << endl; |
} |
void Matrik::matrik_jumlah(const Matrik& matrik1, const Matrik& matrik2){ |
int i, j; |
baris=matrik1.baris; |
kolom=matrik1.kolom; |
for(i=0; i<baris; i++) |
for(j=0; j<kolom; j++) |
A[i][j]=matrik1.A[i][j]+matrik2.A[i][j]; |
} |
void Matrik::kurang_matrik(const Matrik& matrik1, const Matrik& matrik2){ |
for(int i=0; i<matrik1.baris; i++) |
for(int j=0; j<matrik1.kolom; j++) |
A[i][j]=matrik1.A[i][j]-matrik2.A[i][j]; |
} |
void Matrik::assign_matrik(const Matrik& matrik1, const Matrik& matrik2){ |
for(int i=0; i<matrik1.baris; i++){ |
for(int j=0; j<matrik1.kolom; j++) |
matrik1.A[i][j]==matrik2.A[i][j]; |
} |
} |
void Matrik::cetak_matrik(){ |
int i, j; |
for(i=0; i<baris; i++){ |
for(j=0; j<kolom; j++) |
cout << A[i][j] << "\t"; |
cout << endl; |
} |
} |
#endif |
2. Main fungsi
#include <cstdlib> |
#include <iostream> |
#include "matrik.h" |
using namespace std; |
int main(int argc, char *argv[]) |
{ |
int pil; |
Matrik A, B, C; |
Matrik hasil; |
cout << "\t\t\tSelamat Datang di Program Kami\n"; |
cout <<"\t\t\t------------------------------\n"; |
cout <<"Anggota Kelompok :\n"; |
cout <<"1. Adimas Fajar S <09018225>\n"; |
cout <<"2. Adnan Ilham Rifai <09018196>\n"; |
cout <<"3. Nur kahfi Ibrahim <09018238>\n"; |
cout <<"4. Bagus Raditya Wardana <09018231>\n\n"; |
cout << "Matrik Bujur Sangkar (2x2)\n"; |
A.matrik_iden(); |
cout<<endl; |
cout << "Masukan data matrik ordo2x2 \n"; |
A.baca_matrik(); |
cout<<endl; |
A.cetak_matrik(); |
cout << "Determinan Matrik dan Inverse\n"; |
A.determinan_inverse(); |
cout << "\nOperasi-operasi matriks\n\n"; |
cout << "Matrik 1\n"; |
B.baca_matrik(); |
cout<<endl; |
B.cetak_matrik(); |
cout<<endl; |
cout << "Matrik 2\n"; |
C.baca_matrik(); |
cout<<endl; |
C.cetak_matrik(); |
cout<<endl<<endl; |
cout << "Penjumlahan\n"; |
hasil.matrik_jumlah(B, C); |
hasil.cetak_matrik(); |
cout<<endl; |
cout << "Pengurangan\n"; |
hasil.kurang_matrik(B, C); |
hasil.cetak_matrik(); |
cout<<endl<<endl; |
cout << "Memindah isi matrik\n"; |
hasil.assign_matrik(B, C); |
C.cetak_matrik(); |
system("PAUSE"); |
return EXIT_SUCCESS; |
} |
Hasil Compile
Tidak ada komentar:
Posting Komentar