15 May 2012

Program Determinan

#include<iostream.h>

class determinan{
    friend istream& operator >>(istream&, determinan&);
    friend ostream& operator <<(ostream&, const determinan&);
    private :
        int a,b,c,d,hasil;
    public :
        determinan() {};
        int hasilnya(){return (hasil=((a * d) - (b * c)));}
        ~determinan() {};
};

    istream& operator >>(istream& in, determinan& d){
        cout<<"Masukkan bil 1- "; in>>d.a;
        cout<<"Masukkan bil 2- "; in>>d.b;
        cout<<"Masukkan bil 3- "; in>>d.c;
        cout<<"Masukkan bil 4- "; in>>d.d;
        cout<<d.a<<" "<<d.b<<endl;
        cout<<d.c<<" "<<d.d<<endl;

        return in;
    }

    ostream& operator <<(ostream& out, const determinan& d){
        out<<"HAsil determinannnya "<<d.hasil<<endl;

        return out;
    }

    int main(){
        determinan x;
        cin>>x;
        x.hasilnya();
        cout<<x;

        return 0;
    }

0 komentar:

Post a Comment