//methods are defined outside the scope of the class
#include<iostream.h>
#include<conio.h>
class sam
{
private:
float x;
float y;
public:
void get();
void disp();
float sum();
float diff();
float mul();
float div();
}; //End of the class
void sam::get()
{
cout<<"Enter any two numbers"<<endl;
cin>>x>>y;
}
void sam::disp()
{
cout<<"First value="<<x<<endl;
cout<<"Second value="<<y<<endl;
cout<<"Sum="<<sum()<<endl;
cout<<"Diff="<<diff()<<endl;
cout<<"Mul="<<mul()<<endl;
cout<<"Div="<<div()<<endl;
}
float sam::sum()
{
return(x+y);
}
float sam::diff()
{
return(x-y);
}
float sam::mul()
{
return(x*y);
}
float sam::div()
{
return(x/y);
}
void main()
{
clrscr();
sam temp;
temp.get();
temp.disp();
temp.sum();
temp.diff();
temp.mul();
temp.div();
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.