We will learn how to build scientific calculator in c++ .
Functions of this calculator
See more: Program for shutdown your pc
1. Arithmetic operations
2.Trigonometric operations
3.Power functions
4. Log functions
Source code
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<cctype>
#include<cmath>
using namespace std;
int main ()
{
char letter;
char letter1;
char letter2;
char letter3;
char letter4;
int a,b;
double a1,b1;
int result;
double result1;
cout<<“nnn ***************** SCIENTIFIC CALCULATOR ****************** nnn”;
do
{
cout<<“t 1 : Arithmetic Operations n”;
cout<<“t 2 : Trigonometric Functions n”;
cout<<“t 3 : Logarithmic Functions n”;
cout<<“t 4 : Power Functions n”;
cout<<“t 5 : Exit… n”;
letter = getche();
switch(letter)
{
case ‘1’:
{
cout<<“nn”;
cout<<“t1 : Addition n”;
cout<<“t2 : Subtraction n”;
cout<<“t3 : Multipilication n”;
cout<<“t4 : Division nn”;
letter1 = getche();
switch(letter1)
{
case ‘1’:
{
cout<<“nnEnter first number…”;
cin>>a;
cout<<“Enter an other number…”;
cin>>b;
result=a+b;
cout<<“nnResult = “<<result<<endl;
system(“pause”);
break;
}
case ‘2’:
{
cout<<“nnEnter first number…”;
cin>>a;
cout<<“Enter an other number…”;
cin>>b;
result=a-b;
cout<<“nnResult = “<<result<<endl;
system(“pause”);
break;
}
case ‘3’:
{
cout<<“nnEnter first number…”;
cin>>a;
cout<<“Enter an other number…”;
cin>>b;
result=a*b;
cout<<“nnResult = “<<result<<endl;
system(“pause”);
break;
}
case ‘4’:
{
cout<<“nnEnter first number…”;
cin>>a;
cout<<“Enter an other number…”;
cin>>b;
if(a!=0)
{
result=a/b;
cout<<“nnResult = “<<result<<endl;
system(“pause”);
}
break;
}
}// end of inner switch
break;
}// end of case 1 arithmatic operation
case ‘2’:
{
cout<<“nn”;
cout<<“t1 : Sin function n”;
cout<<“t2 : Cos function n”;
cout<<“t3 : Tan function n”;
letter2=getche();
switch(letter2)
{
case ‘1’:
{
cout<<“nn Enter a number…”;
cin>>a1;
result1=(sin(a1));
cout<<“nnResult = “<<result1<<endl;
system(“pause”);
break;
}
case ‘2’:
{
cout<<“nn Enter a number…”;
cin>>a1;
result1=(cos(a1));
cout<<“nnResult = “<<result1<<endl;
system(“pause”);
break;
}
case ‘3’:
{
cout<<“nn Enter a number…”;
cin>>a1;
result1=(tan(a1));
cout<<“nnResult = “<<result1<<endl;
system(“pause”);
break;
}
}// inner switch
break;
}//inner case 2 trignomatic
case ‘3’:
{
cout<<“nn”;
cout<<“t1 : Natural logn”;
cout<<“t2 : log with base 10 n”;
letter3=getche();
switch(letter3)
{
case ‘1’:
{
cout<<“nn Enter a number…”;
cin>>a1;
result1=log(a1);
cout<<“nn Result = “<<result1<<endl;
system(“pause”);
break;
}
case ‘2’:
{
cout<<“nn Enter a number…”;
cin>>a1;
result1= log10(a1);
cout<<“nn Result = “<<result1<<endl;
system(“pause”);
break;
}
}// end of switch
break;
}// end of case 3 logrithmic
case ‘4’:
{
system(“cls”);
cout<<“1) Press 1 for Power n”;
cout<<“2) Press 2 for Square root n”;
cout<<“Enter your choice….”;
letter4=getche();
switch(letter4)
{
case ‘1’:
{
cout<<“nnEnter a number…”;
cin>>a1;
cout<<“Enter power…”;
cin>>b1;
result1=pow(a1,b1);
cout<<“nnResult = “<<result1<<endl;
system(“pause”);
break;
}
case ‘2’:
{
cout<<“nnEnter a number…”;
cin>>a;
result1=sqrt(a);
cout<<“nnResult = “<<result1<<endl;
system(“pause”);
break;
}
}// end of switch
break;
}// end of case power function
}// outer switch
}while(letter != ‘5’);
return 0;
}
Output
Check also: C++ ebook