#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
class Array{
public:
void input();
void kurang();
void kali();
void output();
private:
int n,m,a[10][10], b[10][10], c[10][10],d[10][10];
};
void Array::input(){
cout<<"Masukkan banyak baris : ";cin>>n;
cout<<"Masukkan banyak kolom : ";cin>>m;
cout<<endl;
cout<<"Input Matriks A"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>a[i][j];
}
}
cout<<endl;
cout<<"Input Matriks B"<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout<<"Data ke A["<<i<<"]"<<"["<<j<<"] : ";cin>>b[i][j];
}
}}
void Array::kurang(){
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
c[i][j]=a[i][j]-b[i][j];
}
}
void Array::kali(){
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
d[i][j]=0;
for (int k=1;k<=m;k++)
{
d[i][j]+= a[i][k]*b[k][j];
}
}
}
}
void Array::output(){
cout<<"Matriks A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[i][j]<<" ";
cout<<endl;
}
cout<<endl;
cout<<"Matriks B"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<b[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Pengurangan"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<c[i][j]<<" ";
cout<<endl;
}
cout<<"Hasil Perkalian"<<endl;
cout<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<setw(4)<<d[i][j];
}
cout<<endl;
}
cout<<endl;
cout<<"Transpose Matrik A"<<endl;
cout<<endl;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++)
cout<<setw(5)<<a[j][i]<<" ";
cout<<endl;
}
}
int main(int argc, char *argv[])
{
Array x;
x.input();
x.kurang();
x.kali();
x.output();
system("PAUSE");
return EXIT_SUCCESS;
}
Hasil Compile :
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar