Simple Coding:
#include<iostream.h>#include<conio.h>
void main()
{
clrscr();
int a,b,c;
int n;
cout<<"1.add\n2.sub\n3.mul\n4.div:"<<"\n";
cout<<"select anyone"<<"\n";
cin>>n;
cout<<"enter any two number"<<"\n";
cin>>a>>b;
switch(n)
{
case 1: c=a+b;
cout<<"add="<<c;
break;
case 2: c=a-b;
cout<<"sub="<<c;
break;
case 3: c=a*b;
cout<<"mul="<<c;
break;
case 4: c=a/b;
cout<<"sub"<<c;
break;
default:
cout<<"invalid no.";
}
getch();
}
---------------------------------------------------------------------------------------------------------------------
Coding in Class:
#include<iostream.h>#include<conio.h>
//using namespace std;
class calcu
{
long int a,b,c;
public:
void input()
{
cout<<"\n\n\n\n\t\t\tEnter The First Value = ";
cin>>a;
cout<<"\n\t\t\tEnter The Second Value = ";
cin>>b;
}
void add()
{
c=a+b;
cout<<"\n\n\t\t\tYour Result is = "<<c<<endl;
}
void mul()
{
c=a*b;
cout<<"\n\n\t\t\tYour Result is = "<<c<<endl;
}
void sub()
{
c=a-b;
cout<<"\n\n\t\t\tYour Result is = "<<c<<endl;
}
void div()
{
c=a/b;
cout<<"\n\n\t\t\tYour Result is = "<<c<<endl;
}
};
void main()
{
clrscr();
char ch,ah;
ret1:
calcu c;
c.input();
cout<<"\n\t\t\tEnter The Operator ";
ch=getch();
switch(ch)
{
case '+':
c.add();
break;
case '-':
c.sub();
break;
case '*':
c.mul();
break;
case '/':
c.div();
break;
default:
cout<<"\n\t\t\tError\n";
}
cout<<"\n\t\t\tEnter 1 For Try Again\n\t\t\tEnter 2 For End";
ah=getch();
if (ah=='1')
{
clrscr();
goto ret1;
}
else
getch();
}
Simple Code:
Class Code:
#Chauhan
Post A Comment:
0 comments so far,add yours