Numerical Operations using Control Strucure..
CODE:
#include<iostream.h>
#include<conio.h>
#include<math.h>
class num
{
public:
int a,b;
void add()
{
cout<<"\nEnter the two values";
cin>>a>>b;
cout<<"\nOutput:"<<a+b;
}
void sub()
{
cout<<"\nEnter the two values";
cin>>a>>b;
cout<<"\nOutput:"<<a-b;
}
void mul()
{
cout<<"\nEnter the two values";
cin>>a>>b;
cout<<"\nOutput:"<<a*b;
}
void div()
{
cout<<"\nEnter the two values";
cin>>a>>b;
cout<<"\nOutput:"<<a/b;
}
};
void main()
{
int n,s;
clrscr();
num obj;
do
{
cout<<"\nSelect your option";
cout<<"\n\t\t1.Addition\n\t\t2.Subtraction\n\t\t3.Multiplication\n\t\t4.Division\n\t\t5.Eit\n";
cout<<"\nEnter the case...";
cin>>n;
switch(n)
{
case 1:
{
obj.add();
break;
}
case 2:
{
obj.sub();
break;
}
case 3:
{
obj.mul();
break;
}
case 4:
{
obj.div();
break;
}
default:
{
clrscr();
cout<<"\nSorry!!\nYou have entered an wrong value..";
goto exit;
}
}
}
while(n!=5);
exit:
getch();
}
Comments
Post a Comment