#include <cstdlib>
#include <iostream>
#include <iomanip.h>
using namespace std;
class aku{
friend istream& operator >>(istream&, aku&);
friend ostream& operator <<(ostream&, aku&);
public :
aku();
void proses();
private :
int i,j,a[10][10],b[10][10],hasil[100][100],baris,kolom;
};
aku::aku(){baris=3,kolom=3;}
istream& operator >>(istream& in,aku& x){
//cout<<"Banyak baris : "; in>>x.baris;
//cout<<"Banyak kolom : "; in>>x.kolom;
cout<<endl;
cout<<"Matriks A : " <<endl;
for(x.i=0;x.i<x.baris;x.i++)
for(x.j=0;x.j<x.kolom;x.j++){
cout<<"Data [" <<x.i+1 <<"][" <<x.j+1 <<"] : "; in>>x.a[x.i][x.j];
}
cout<<endl <<"Matriks B : " <<endl;
for(x.i=0;x.i<x.baris;x.i++)
for(x.j=0;x.j<x.kolom;x.j++){
cout<<"Data [" <<x.i+1 <<"][" <<x.j+1 <<"] : "; in>>x.b[x.i][x.j];
}
}
void aku::proses(){
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++)
hasil[i][j]=a[i][j] + b[i][j];
}
ostream& operator <<(ostream& out, aku& x){
x.proses();
cout<<endl <<endl <<"Hasil Penjumlahan Matriks A & B Yaitu : " <<endl;
for(x.i=0;x.i<x.baris;x.i++){
for(x.j=0;x.j<x.kolom;x.j++)
cout<<setw(4) <<x.a[x.i][x.j];
cout<<" ";
for(x.j=0;x.j<x.kolom;x.j++)
cout<<setw(4) <<x.b[x.i][x.j];
cout<<" ";
for(x.j=0;x.j<x.kolom;x.j++)
cout<<setw(4) <<x.hasil[x.i][x.j];
cout<<" ";
cout<<endl <<endl;
}
}
int main(int argc, char *argv[])
{
aku x;
cout<<endl;
cout<<"PENJUMLAHAN 2 MATRIKS YANG BERORDO 3x3" <<endl;
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++++" <<endl <<endl;
cin>>x;
cout<<endl <<"++++++++++++++++++++++++++++++++++++++" <<endl;
cout<<x;
cout<<"++++++++++++++++++++++++++++++++++++++" <<endl;
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar