#include "iostream.h"
#include "conio.h"
#include "iomanip.h"
#include "stdlib.h"
const int Max=10;
class ang
{
private:
int baris;
int kolom;
float data[Max][Max];
public:
ang();
void input();
void output();
ang operator + (ang);
ang operator - (ang);
ang operator * (ang);
};
ang::ang()
{
baris=0;
kolom=0;
int a,s;
for(a=0;a<Max; a++)
for(s=0;s<Max; s++)
data[a][s]=0;
}
void ang::input()
{
int a,s;
do
{
cout<<"Masukkan Data ! :"<<endl;
cout<<"Jumlah Baris : ";
cin>>baris;
} while (baris>Max);
do
{
cout<<"Jumlah Kolom : ";
cin>>kolom;
} while (kolom>Max);
for(a=0; a<baris; a++)
for(s=0; s<kolom; s++)
{
cout<<"Data
["<<a+1<<","<<s+1<<"] = ";
cin>>data[a][s];
}
}
void ang::output()
{
int q,w;
for(q=0;q<baris;q++)
{
for(w=0;w<kolom;w++)
cout<<setw(8)<<data[q][w];
cout<<endl;
}}
ang ang::operator + (ang m2)
{
int z,x;
ang hasil;
hasil.baris=baris;
hasil.kolom=kolom;
for(z=0;z<baris;z++)
for(x=0;x<baris;x++)
hasil.data[z][x]=data[z][x] + m2.data[z][x];
return(hasil);
}
ang ang::operator - (ang m2)
{
int z,x;
ang hasil;
hasil.baris=baris;
hasil.kolom=kolom;
for(z=0;z<baris;z++)
for(x=0;x<baris;x++)
hasil.data[z][x]=data[z][x] - m2.data[z][x];
return(hasil);
}
ang ang::operator * (ang m2)
{
int z,x;
ang hasil;
hasil.baris=baris;
hasil.kolom=kolom;
for(z=0;z<baris;z++)
for(x=0;x<baris;x++)
hasil.data[z][x]=(data[z][x] * m2.data[z][x])+(data[z][x] *
m2.data[z][x]);
return(hasil);
}
void main()
{
cout<<"=> PROGRAM MATRIKS <="<<endl;
ang ang1;
cout<<"\n>>>>>Matriks A "<<endl;
ang1.input();
ang ang2;
cout<<"\n>>>>>Matriks B : "<<endl;
ang2.input();
clrscr();
cout<<" Matriks
A \n"<<endl;
ang1.output();
cout<<endl;
cout<<" Matriks
B \n"<<endl;
ang2.output();
cout<<endl;
ang ang3;
ang3 = ang1 + ang2;
cout<<"\nHASIL PENJUMLAHAN : "<<endl;
ang3.output();
ang3 = ang1 - ang2;
cout<<"\nHASIL PENGURANGAN : "<<endl;
ang3.output();
ang3 = ang1 * ang2;
cout<<"\nHASIL PERKALIAN : "<<endl;
ang3.output();
}
No comments:
Post a Comment