//========================================
/* Object Oriented Programming : Class*/
//========================================
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
class A_and_B
{ private:
int a,b,result;
public:
void inputData(void)
{ cout<<"\nInput a,b :";
cin>>a>>b;
int x=a,y=b;
}
//-----------------------
int Sums()
{ return (a+b);
}
//-----------------------
void Swap(void)
{ int x;
x=a;
a=b;
b=x;
}
//-----------------------
void Displays(string);
};
//------------------------------------------
//------------------------------------------
void A_and_B::Displays(string st)
{ cout<<st;
cout<<"a="<<a<<", b="<<b<<endl;
}
//-------------------------------------------
//-------------------------------------------
int main()
{ A_and_B Obj;
system("clear");
Obj.inputData();
Obj.Displays("Before swap :");
Obj.Swap();
Obj.Displays("After swap :");
cout<<"\nSum a+b = "<<Obj.Sums()<<endl;
return 0;
}
No comments:
Post a Comment