This program illustrates how to implement the arithmetic operation in an object oriented way.
Here we have a class with 2 variables. For each operation an object of this class is created to do the operation instead of declaring such much variables. Therefore, this method is, for a large scale implementation, is quite efficient.
so have a try on it.
Program:
//simple operations in object oriented method
#include<conio.h>
#include<iostream.h>
class dom
{
int a,b;
public:
void get()
{
cout<<"oops..!\nnumbers:";
cin>>a>>b;
cout<<"passed";
}
void add()
{
cout<<endl<<"a+b="<<a+b;
}
void diff()
{
cout<<endl<<"a-b="<<a-b;
}
void mult()
{
cout<<endl<<"a*b="<<a*b;
}
void div()
{
cout<<endl<<"a/b="<<a/b;
}
};
void main()
{
clrscr();
dom add, mult,diff,div;
cout<<"\n+";
add.get();
cout<<"\n-";
diff.get();
cout<<"\n*";
mult.get();
cout<<"\n/";
div.get();
cout<<"\n\nprocessing...";
add.add();
diff.diff();
mult.mult();
div.div();
cout<<"\n\nover";
getch();
}
Have u tried this?
Comments
Post a Comment