Algoritma Jumlah, Kurang, Kali, Bagi {menampilkan hasil jumlah, kurang, klai, bagi } |
| Deklarasi : p : integer x : integer y : integer hasil : double |
| Deskripsi : ostr<<"TOTAL JUMLAH : "<<p.x+p.y<<endl; ostr<<"TOTAL KURANG : "<<p.x-p.y<<endl; ostr<<"TOTAL KALI : "<<p.x*p.y<<endl; ostr<<"TOTAL BAGI : "<<p.x/p.y<<endl; |
Listing
| #include <cstdlib> |
| #include <iostream> |
| |
| using namespace std; |
| class jumlah{ |
| friend istream& operator>>(istream&,jumlah&); |
| friend ostream& operator<<(ostream&,const jumlah&); |
| public : |
| jumlah (int a=0,int b=0):x(a),y(b) {} |
| double hasil(); |
| // operator double()const; |
| private: |
| double x,y; |
| double jum; |
| // void reduce(); |
| }; |
| int main(int argc, char *argv[]) |
| { |
| int jum; |
| jumlah a,b; |
| //jumlah b; |
| cin>>a; |
| cin>>b; |
| |
| cout<<a<<endl; |
| cout<<b<<endl; |
| |
| //jum=(a+b); |
| // cout<<jum; |
| system("PAUSE"); |
| return EXIT_SUCCESS; |
| } |
| |
| //jumlah::jumlah (int a) { |
| //x+y; |
| // } |
| |
| //jumlah::operator double(){ |
| // return double x+y;} |
| double jumlah::hasil(){ |
| return x+y;} |
| |
| istream& operator>>(istream& istr,jumlah& p){ |
| cout<<"Masukan Nilai ke-1 : ";istr>>p.x; |
| cout<<"Masukan Nilai ke-2 : ";istr>>p.y; |
| cout<<endl; |
| return istr; |
| |
| } |
| ostream& operator<<(ostream& ostr,const jumlah& p){ |
| ostr<<"TOTAL JUMLAH : "<<p.x+p.y<<endl; |
| ostr<<"TOTAL KURANG : "<<p.x-p.y<<endl; |
| ostr<<"TOTAL KALI : "<<p.x*p.y<<endl; |
| ostr<<"TOTAL BAGI : "<<p.x/p.y<<endl; |
| return ostr; |
| } |
Tidak ada komentar:
Posting Komentar