Menghitung Determinan Matriks Ordo 2×2

#include <iostream.h>
#include <conio.h>

class matrik{

// mendiskripsikan overloading input dan output
friend ostream& operator<<(ostream&, const matrik&);

friend istream& operator>>(istream&, matrik&);
private:
int a,b,c,d,det;
// mendeskripsikan fungsi yang di butuhkan.
public:
matrik();
void determinan(){
det=a*d-c*b;
}
void cetak();
};
// pendeklarasian overloading input
istream& operator>>(istream& in, matrik& masukan){
cout<<“\nmasukkan nilai ke [1,1]”;in>>masukan.a;
cout<<“masukkan nilai ke [1,2]”;in>>masukan.b;
cout<<“masukkan nilai ke [2,1]”;in>>masukan.c;
cout<<“masukkan nilai ke [2,2]”;in>>masukan.d;
}
// pendeklarasian overloading output.
ostream& operator<<(ostream& out, const matrik& keluaran){
cout<<“\nnilai determinannya : “;out<<keluaran.det;
}

matrik::matrik(){
cout<<“\n            WELCOME\n”;
}

void matrik::cetak(){

cout<<“\nMatriks\n”;
cout<<a<<”    “<<b<<endl<<endl;
cout<<c<<”    “<<d<<endl;
}

main(){
matrik x; // pemanggilan class
cin>>x;
x.cetak();
x.determinan();
cout<<x;
return 0;
}

hasilnya adalah :

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: