Selasa, 29 Maret 2011

PENJUMLAHAN

#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