#include<iostream.h>
#include<conio.h> // for clrscr()
class calc
{
public:
static int last;
static int count;
int a;
int b;
char c;
void init(void)
{
last = 0;
count=0;
}
void perform(int,int,char);
static void lasters(void)
{
cout<<"\nLast Result :"<<last<<"\n";
cout<<"Operations performed so far :"<<count<<"\n";
}
};
int calc :: last=0;
int calc :: count=0;
void calc :: perform(int i, int j, char ch)
{
a=i;
b=j;
c=ch;
cout<<"\n";
switch(ch)
{
case '+' : last = a + b;
break;
case '-' : last = a - b;
break;
case '*' : last = a * b;
break;
case '/' : last = a / b;
break;
case '%' : last = a % b;
break;
default : cout<<"Error!!";
break;
}
count++;
cout<<last<<"\n";
}
int main()
{
clrscr();
calc X;
int x, y;
X.init();
char k, ch;
do
{
cout<<"Enter two integer:";
cin>>x>>y;
cout<<"\n"<<"Enter operator(+, -, *, /, %):";
cin>>k;
cout<<"\n";
//object created
X.perform(x,y,k);
X.lasters();
cout<<"\n\n\n Want to perform more operation ? (y/n..";
cin>>ch;
cout<<endl;
}while (ch=='y' || ch =='Y');
return 0;
}
Write a C++ program to simulate an arithmetic calculator for
Integers. The program should be able to produce the result calculated
And the numbers of arithmetic operators performed so far. Any
Wrong operation is to be reported.