C++ Class 12 Standard Calculator
C++ Class 12 Standard Calculator
cin>>ch;
Process(ch);
}
};
class Bin_Con
{
int a,b,c; int Bin_arr[20];
void Conv_1();
void Conv_2();
public:
void Show();
void Process(int);
};
void Bin_Con::Show()
{
cout<<"***********************************";
cout<<"\n\n**Welcome To Binary Conversions**\n";
cout<<"***********************************";
cout<<"\n\n\tEnter your choice\n";
cout<<"\n\t1. Decimal to Binary\n";
cout<<"\t2. Binary to Decimal\n\t";
cin>>c;
Process(c);
}
void Bin_Con::Process(int c)
{
switch(c)
{
case 1:
Conv_1();
break;
case 2:
Conv_2();
break;
default:
cout<<"\nINVALID CHOICE!!\n";
}
}
void Bin_Con::Conv_1()
{
cout<<"\nEnter Decimal number to be converted to Binary\n";
cin>>a;
while (a!=1)
{
b=a%2;
cout<<b<<endl;
a=a/2;
if (a==1)
{
cout<<a;
break;
}
}
cout<<"\n\nNOTE:- Read from Bottom to Top\n";
}
void Bin_Con::Conv_2()
{
cout<<"\nEnter number of digits in Binary Number\n";
cin>>a;
cout<<"Enter the digits of Binary Number\n";
for(b=0;b<a;b++)
{
cin>>Bin_arr[b];
}
c=0;
for(b=0;b<a;b++)
{
c=c+(Bin_arr[b]*(pow(2,b)));
}
cout<<"Decimal representation of given Binary number is "<<c;
}
void Std_Calc::Show()
{
cout<<"\n\n\tEnter your choice:\n\n";
cout<<"\n\t1. Addition\n\t2. Multiplication\n\t3. Subt
raction(a-b)\n\t4. Division(a/b)\n\t5. Modulus(a%b)\n\n\t";
cin>>ch;
cout<<"\n\t Enter two numbers (a and b):\n\t ";
cin>>a;cout<<"\t ";cin>>b;
switch(ch)
{
case '1':
c=a+b;
cout<<"\nResult is "<<c<<endl;
break;
case '2':
c=a*b;
cout<<"\nResult is "<<c<<endl;
break;
case '3':
c=a-b;
cout<<"\nResult is "<<c<<endl;
break;
case '4':
if(b!=0)
{
c=(float)a/b;
cout<<"\nResult is "<<c
<<endl;
}
else
cout<<"\nDivision by zero is I
NVALID!!!\n\n";
break;
case '5':
if(b!=0)
{
d=a%b;
cout<<"\nResult is "<<
d<<endl;
}
else
cout<<"\nDivision by zer
o is INVALID!!!\n\n";
break;
default : cout<<"\nINVALID CHOICE!!!!\n\n";
}
}
void Sci_Calc::Process(int a)
{
switch(a)
{
case 1:
Fact();
break;
case 2:
npr_func();
break;
case 3:
ncr_func();
break;
case 4:
t_ratio();
break;
case 5:
h_func();
break;
case 6:
pow_e();
break;
case 7:
sQrt();
break;
case 8:
n_root();
break;
case 9:
fract_root();
break;
case 10:
nat_log();
break;
case 11:
com_log();
break;
case 12:
Std_Calc::Show();
break;
default : cout<<"\nInvalid choice!!";
}
}
void Sci_Calc::Fact()
{
cout<<"\n\nEnter number\n";
cin>>n;
f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
cout<<"\nFactorial of "<<n<<" is "<<f;
}
void Sci_Calc::npr_func()
{
cout<<"\n\nEnter numbers\n";
cin>>n>>r;
f=1;
for(i=1;i<=n;i++)
{
f*=i;
}
c=1;
for(i=1;i<=(n-r);i++)
{
c*=i;
}
npr = f/c;
cout<<"\nNpr : "<<npr;
}
void Sci_Calc::ncr_func()
{
cout<<"\n\nEnter numbers\n";
cin>>n>>r;
f=1;
for(i=1;i<=n;i++)
{
f*=i;
}
c=1;
for(i=1;i<=(n-r);i++)
{
c*=i;
}
a=1;
for(i=1;i<=r;i++)
{
a*=i;
}
ncr=f/(c*a);
cout<<"\nNcr : "<<ncr;
}
void Sci_Calc::t_ratio()
{
cout<<"\n\nEnter number (angle): ";
cin>>n;
cout<<"\nEnter Trignometric Ratio : ";
cout<<"1. Sine\n";
cout<<"2. Cosine\n";
cout<<"3. Tangent\n";
cout<<"4. Cotangent\n";
cout<<"5. Secant\n";
cout<<"6. Cosecant\n";
cin>>c_h;
switch(c_h)
{
case 1:
f=sin(n);
break;
case 2:
f=cos(n);
break;
case 3:
f=tan(n);
break;
case 4:
f= 1/(tan(n));
break;
case 5:
f=1/(cos(n));
break;
case 6:
f=1/(sin(n));
break;
default:
cout<<"\nInvalid Choice!!\n";
}
cout<<"\nTrignometric Ratio of angle "<<n<<" is "<<f;
}
void Sci_Calc::h_func()
{
cout<<"\n\nEnter number(angle) : ";
cin>>n;
cout<<"\nEnter your choice : ";
cout<<"\n1. Cosh\n";
cout<<"2. Sinh\n";
cout<<"3. Tanh\n";
cin>>c_h;
switch(c_h)
{
case 1:
f=cosh(n);
break;
case 2:
f=sinh(n);
break;
case 3:
f=tanh(n);
break;
default:
cout<<"\nInvalid choice\n";
}
cout<<"\nHyperbolic function of "<<n<<" is "<<f;
}
void Sci_Calc::pow_e()
{
cout<<"\n\nEnter number : ";
cin>>n;
f=exp(n);
cout<<"\nValue of e raised to "<<n<<" is "<<f;
}
void Sci_Calc::sQrt()
{
switch(ch1)
{
case 1:
ob1.Show_m();
break;
case 2:
ob2.Show();
break;
case 3:
ob3.Show();
break;
default:
cout<<"\nINVALID CHOICE!!!\n";
}
cout<<"\nWant another? (Y or N)\n";
cin>>ch;
clrscr();
while(ch!='\0')
{
if((ch=='y'||ch=='Y')||(ch=='n'||ch=='N'))
{
break;
}
else
{
cout<<"INVALID CHOICE!!! Enter choice again ";
}
cin>>ch;
if((ch=='y'||ch=='Y')||(ch=='n'||ch=='N'))
{ clrscr();
break;
}
else
{ clrscr();
continue;
}
}
}
}