Program Mencari Invers Matrix 2×2

program ini saya buat untuk menyelesaikan tugas dari asdos saya dalam praktikum algoritma pemrograman dengan c++ saat semester 2 kemarin.

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

class ordo{
private :
int i,j,matrik[10][10];
float hasilbagi,det,a,b,c,d;
friend ostream& operator<<(ostream&, const ordo&);
friend istream& operator>>(istream&, ordo&);
public :
void determinan(){
det=(matrik[0][0] * matrik[1][1]) – (matrik[1][0] * matrik[0][1]);
cout<<“\nmaka determinannya adalah = “;
cout<<det<<endl;
}
void invers(){
hasilbagi = 1/det;
a = hasilbagi * matrik[1][1];
b= hasilbagi * -matrik[0][1];
c = hasilbagi * -matrik[1][0];
d = hasilbagi * matrik[0][0];

cout<<“matrik invers \n\n=”<<“1/”<<det<<” x [“<<matrik[1][1]<<” “<<-matrik[0][1]<<“]”;
cout<<“\n         [“<<-matrik[1][0]<<” “<<matrik[0][0]<<“]”;
cout<<“\n\n jadi matrik inversnya adalah = \n”;
cout<<“[“<<a<<” “<<b<<“]”<<endl;
cout<<“[“<<c<<” “<<d<<“]”;
}
};

istream& operator>>(istream& in, ordo& A){
cout<<“invers matrik 2×2″<<endl;
for(A.i=0;A.i<=1;A.i++){
for(A.j=0;A.j<=1;A.j++){
cout<<“matrik [“<<A.i<<“][“<<A.j<<“] =”; cin>>A.matrik[i][j]; }}
return in;
}

ostream& operator<<(ostream& out ordo& B){
for(B.i=0;B.i<=1;B.i++){
for(B.j=0;B.j<=1;B.j++){
cout<<B.matrik[i][j]<<” “; }
cout<<endl;
}
return out;
}

void main(){
ordo x;

cin>>x;
cout<<x;
x.determinan();
x.invers();
}

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