MATRIK

36106yqar2xkebp1.jpg36106yqar2xkebp1.jpg36106yqar2xkebp1.jpg

/*——————————————————*/
/* PROGRAM C++ */
/*——————————————————*/
/* Nama: M. Zakqi Hendra A */
/* Kelas:2A */
/* Tanggal: */
#include<iostream.h>
#include<conio.h>

class Matrik
{
private:
int M[2][2];
public:
Matrik();
void info();
Matrik Tambah (Matrik Mat);
Matrik Kurang (Matrik Mat);
Matrik Kali (Matrik Mat);
};

Matrik::Matrik()
{
M[0][0]=1;
M[0][1]=2;
M[1][0]=3;
M[1][1]=4;
}

void Matrik::info()
{

cout<<“Isi Matrik=”<<endl ;
cout<<M[0][0]<<” “<<M[0][1]<<endl;
cout<<M[1][0]<<” “<<M[1][1]<<endl;

}

Matrik Matrik:: Tambah(Matrik Mat)
{

Matrik tmp;
tmp.M[0][0]=M[0][0]+Mat.M[0][0];
tmp.M[0][1]=M[0][1]+Mat.M[0][1];
tmp.M[1][0]=M[1][0]+Mat.M[1][0];
tmp.M[1][1]=M[1][1]+Mat.M[1][1];
return(tmp);
}

Matrik Matrik:: Kurang(Matrik Mat)
{

Matrik tmp;
tmp.M[0][0]=M[0][0]-Mat.M[0][0];
tmp.M[0][1]=M[0][1]-Mat.M[0][1];
tmp.M[1][0]=M[1][0]-Mat.M[1][0];
tmp.M[1][1]=M[1][1]-Mat.M[1][1];
return(tmp);
}

Matrik Matrik:: Kali(Matrik Mat)
{

Matrik tmp;
tmp.M[0][0]=(M[0][0]*Mat.M[0][0])+(M[0][1]*Mat.M[1][0]);
tmp.M[0][1]=(M[0][0]*Mat.M[0][1])+(M[0][1]*Mat.M[1][1]);
tmp.M[1][0]=M[1][0]*Mat.M[0][0]+(M[1][1]*Mat.M[1][0]);;
tmp.M[1][1]=M[1][0]*Mat.M[0][1]+(M[1][1]*Mat.M[1][1]);;
return(tmp);

}
void main()
{
clrscr();
Matrik Mat1,Mat2,Mat3,Mat4,Mat5,Mat6,Mat7,Mat8,Mat9;
cout<<“==================”<<endl;
cout<<“MATRIK TAMBAH”<<endl;
Mat3=Mat1.Tambah(Mat2);
Mat1.info();
Mat2.info();
Mat3.info();
cout<<“==================”<<endl;
cout<<“MATRIK KURANG”<<endl;
Mat3=Mat3.Kurang(Mat4);
Mat4.info();
Mat5.info();
Mat6.info();
cout<<“==================”<<endl;
cout<<“MATRIK KALI”<<endl;
Mat9=Mat7.Kali(Mat8);
Mat7.info();
Mat8.info();
Mat9.info();

getch();
}

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: