Home » » Determinan Program

Determinan Program

Posted by Agus Nur Ikhsan on Minggu, 20 November 2011

Let’s see my source code now ..
1 #include<iostream.h>
2  
3 class determinan{
4                 friend istream& operator >>(istream&, determinan&);
5                 friend ostream& operator <<(ostream&, const determinan&);
6                 private :
7                                 int a,b,c,d,hasil;
8                 public :
9                                 determinan() {};
10                                 int hasilnya(){return (hasil=((a * d) – (b * c)));}
11                                 ~determinan() {};
12 };
13                 istream& operator >>(istream& in, determinan& d){
14                                 cout<<”Masukkan bil 1- =”; in>>d.a;
15                                 cout<<”Masukkan bil 2- =”; in>>d.b;
16                                 cout<<”Masukkan bil 3- =”; in>>d.c;
17                                 cout<<”Masukkan bil 4- =”; in>>d.d;
18                                 cout<<d.a<<” “<<d.b<<endl;
19                                 cout<<d.c<<” “<<d.d<<endl;
20                                 return in;
21                 }
22                 ostream& operator <<(ostream& out, const determinan& d){
23                                 out<<”Hasil determinannnya =”<<d.hasil<<endl;
24                                 return out;
25                 }
26                 int main(){
27                                 determinan x;
28                                 cin>>x;
29                                 x.hasilnya();
30                                 cout<<x;
31  
32     system(“PAUSE”);
33     return EXIT_SUCCESS;
34                 }

The explanation:
  • I use “class determinan” for this program in step 3.
  • I give the operator overloading in step 4 and 5.
  • I declared the private in step 6 and 7.
  • Then the private in step 8 to 11.
  • In step 13 to 24 is the execution for operator overloading.
  • Main function in step 26 to 20.
  • The class name n object called by steps 29 and 30.
Let’s go to the result :

Thanks for reading & sharing Agus Nur Ikhsan

Previous
« Prev Post

0 komentar:

Posting Komentar

Popular Posts