#include<iostream>
#include<conio>
class calc
{
public:
void add()
{
int a,b,c;
cout<<"enter the values"<<endl;
cin>>a>>b;
c=a+b;
cout<<"result is "<<c<<endl;
}
void sub()
{
int aa,bb,cc;
cout<<"enter the values"<<endl;
cin>>aa,bb;
cc=aa-bb;
cout<<"result is "<<cc<<endl;
}
void mul()
{
int aaa,bbb,ccc;
cout<<"enter the values"<<endl;
cin>>aaa>>bbb;
ccc=aaa*bbb;
cout<<"result is "<<ccc<<endl;
}
};
main()
{
calc q;
char ch;
cout<<"enter the choice"<<endl;
cin>>ch;
switch(ch)
{
case 'A':
q.add();
break;
case 'S':
q.sub();
break;
case'M':
q.mul();
break;
default:
cout<<"invalid input"<<endl;
}
getch();
}
#include<conio>
class calc
{
public:
void add()
{
int a,b,c;
cout<<"enter the values"<<endl;
cin>>a>>b;
c=a+b;
cout<<"result is "<<c<<endl;
}
void sub()
{
int aa,bb,cc;
cout<<"enter the values"<<endl;
cin>>aa,bb;
cc=aa-bb;
cout<<"result is "<<cc<<endl;
}
void mul()
{
int aaa,bbb,ccc;
cout<<"enter the values"<<endl;
cin>>aaa>>bbb;
ccc=aaa*bbb;
cout<<"result is "<<ccc<<endl;
}
};
main()
{
calc q;
char ch;
cout<<"enter the choice"<<endl;
cin>>ch;
switch(ch)
{
case 'A':
q.add();
break;
case 'S':
q.sub();
break;
case'M':
q.mul();
break;
default:
cout<<"invalid input"<<endl;
}
getch();
}
Calculator in C++ using Class |
Post a Comment