b374k
v10
today : | at : | safemode : ON
> / home / facebook / twitter / youtube /
name author perms com modified label

Addition operator used the overloading pramana rwxr-xr-x 0 11:58 pm

Filename Addition operator used the overloading
Permission rw-r--r--
Author pramana
Date and Time 11:58 pm
Label
Action
Addition operator is a mathematical operation in which these operations will add up the numbers in the input .... I've created this program using function overloading for overloading which defines the functions that we have created .....

this is source code (c + +)


#include <cstdlib>
#include <iostream>

using namespace std;




//declared class
class kenapa{
      friend istream& operator>>(istream&, kenapa&);
      friend ostream& operator<<(ostream&, kenapa&);
      public://declared function
             kenapa();
             void tambah();
      private://declared data type
              int x,y,z;
      };
     
kenapa::kenapa(){
             cout<<"Operator addition"<<endl;
             }
//function
void kenapa::tambah(){
     z=x+y;
     }
//this for input    
istream& operator>>(istream& in, kenapa& masuk){
         cout<<"Enter first number : ";
         in>>masuk.x;
         cout<<"Enter second number : ";
         in>>masuk.y;
         }
 

//this for output        
ostream& operator<<(ostream& out, kenapa& keluar){
         cout<<"Result is : ";
         out<<keluar.z<<endl;
         }

int main(int argc, char *argv[])
{
    kenapa mantap;
    cin>>mantap;//call function input
    mantap.tambah();//call function process
    cout<<mantap;//call function output
    system("PAUSE");
    return EXIT_SUCCESS;
}
 

0 comments:

Post a Comment

 

Jayalah Indonesiaku © 2010 Pramana's BLOG
VB (Vio b374k) Template design by p4r46hcyb3rn3t