Professional Documents
Culture Documents
Department of Computer Science and Engineering
Department of Computer Science and Engineering
Department of Computer Science and Engineering
Create a calculator using class in which add and sub is defined with in the class nd two functions
outside the class.
#include<iostream.h>
#include<conio.h>
class calculator
{
public:
void add()
{
int a,b;
cout << "Enter first number:";
cin >> a;
cout << "Enter second number:";
cin >> b;
cout << "addition is :" << a+b;
}
void sub(){
int a,b;
cout << "Enter first number:";
cin >> a;
cout << "Enter second number:";
cin >> b;
Prabhjot kaur
13BCS1184
void divi();
};
void calculator::multi()
{
int a,b;
cout<<"enter first number";
cin>>a;
cout<<"enter second number";
cin>>b;
cout<<"multiplication is :"<<a*b;
}
void calculator::divi()
{
int a,b;
cout<<"enter first number";
cin>>a;
cout<<"enter second number";
cin>>b;
cout<<"division is:"<<a/b;
}
Prabhjot kaur
13BCS1184
int main()
{
calculator calc;
int get;
for(int i=0;i<=4;i++)
{
cout << "\n\nPress:\n\t1 : addition\n\t2 : subtraction\n\t3 : multiplication\n\t4 :
division\n\t0 : quit\n";
cin >> get;
if(get==1){
calc.add();
} else if(get==2){
calc.sub();
} else if(get==3){
calc.multi();
} else if(get==4){
calc.divi();
} else{
break;
}
}
return 0;
}
Prabhjot kaur
13BCS1184
Output
Prabhjot kaur
13BCS1184