Filename | Addition operator used the overloading |
Permission | rw-r--r-- |
Author | pramana |
Date and Time | 11:58 pm |
Label | Alpro cases |
Action |
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