Department of Computer Science and Engineering

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

cout << "subtraction is :" << a-b;


}
void multi();

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Output

Prabhjot kaur
13BCS1184

You might also like