//Program to perform algebric operations using a member function methods defined within the scope of the class definition
#include<iostream.h>
#include<conio.h>
class sample
{
private:
float x;
float y;
public:
void get()
{
cout<<"enter any two number"<<endl;
cin >>x>>y;
}
void disp()
{
cout<<"First value = " <<x<<endl;
cout<<"Second value = "<<y<<endl;
cout<<"sum = "<<sum()<<endl;
cout<<"sub = "<<sub()<<endl;
cout<<"mul = "<<mul()<<endl;
cout<<"div = "<<div()<<endl;
}
float sum()
{
return(x+y);
}
float sub()
{
return(x-y);
}
float mul()
{
return(x*y);
}
float div()
{
return (x/y);
}
};
void main()
{
clrscr();
sample temp;
temp.get();
temp.disp();
temp.sum();
temp.sub();
temp.mul();
temp.div();
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.