Menu Driven Standard AND Scientific Calculator: Abstract
Menu Driven Standard AND Scientific Calculator: Abstract
AND
SCIENTIFIC CALCULATOR
Abstract:
Mathematical programming, together with subordinate programming languages, is the
backbone of any programming language and one of the most important reasons to use
computers. That is because nearly all sciences in the world are dependent on mathematics.
Then, the need for easier methods to do mathematics continues to be one of the most required
things nowadays and will still be obtainable until the end of the world. So, from this point, we are
working to implement a scientific calculator. In C++, some libraries function in mathematics such
as math.h and c math, but these libraries don't give you all the operations one needs, however,
they are the basis on which we build our implementation.
Have you ever tried to put the upper formula in one of your programs, but you found it hard
to be calculated? Have you ever stopped writing one of your programs because you need to use
complex formulas and there isn't a way to calculate them in your programming language? Have
you gone to use programming languages, because you need to use some of their mathematical
power, although at the same time if you have this power in your main language you may
produce a better program?
Therefore, our team has come up with the idea of a menu-driven calculator that performs
Standard and Scientific calculations with the following concepts using c++ which includes the
given below learning objectives:
● Use of c++ classes with static functions
● Generation and calling static functions
● Use the functions of Math.h header file
● Develop and display the main menu and its submenus
1. Introduction:
The Menu Based Calculation System project is aimed at performing different types of
calculations including normal and scientific calculations. In this project, two calculators Standard
and Scientific, are used for performing calculations.
2. Objective:
The Standard calculator helps in performing simple calculations such as addition, multiplication,
etc. while the Scientific calculator helps in performing calculations such as finding the squares
or cube of a number.
3. Class Diagram:
UML Class Diagram
4. Code:
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define new_cal 1
#define old_cal 0
};
/*division function will divide the first number by the second number. This function accepts two
arguments, one is a copy of a variable and another is a pointer type because if accepting divisor
s zero, then this function will show a message to enter the divisor again. Using pointer means
that the entered value of the divisor for this function should be updated at the main
function also.*/
/*Modulus function will divide the first number by the second number and return the remaining
part of the division. Similar to the division function, it will not accept zero in the divisor. Modulus
cannot be performed on a double number, so we need to convert
it into an integer.*/
*a = x ;
*b = y ;
return(x%y);
double scien_calc::cube(double x)
{
return(pow(x , 3)) ;
double scien_calc::sq_root(double x)
{
return(sqrt(x)) ;
}
/*Factorial function of the scien_calc class to return a long integer as the factorial of an
acceptable number. This will convert the accepting number into an integer before calculating the
factorial.*/
long int scien_calc::fact(double x)
{
int n = (int)x;
long int f = 1;
while(n > 1)
{
f*=n ;
n--;
}
return f ;
}
double scien_calc::sin_func(double x)
{
return(sin(x)) ;
}
double scien_calc::cos_func(double x)
{
return(cos(x)) ;
}
double scien_calc::tan_func(double x)
{
return(tan(x)) ;
}
//Loop of the main menu from where the program starts. It will show the menu to choose the
type of calculator.
do
{
cout << "\n========Type of Calculators=======";
cout << "\n1\tStandard Calculator\n2\tScientific Calculator\n3\tQuit";
cout << "\nChoose the type of Calculator:";
cin >> choice1;
flag = new_cal ;
switch(choice1)
{
case 1:
//Option 8 will be displayed only when working on old calculations. Here, already a number
is saved in calculator memory.
if(flag == old_cal)
cout << "\n8\tClear Memory";
switch(choice2)
{
case 1:
//If a new calculation is there, then accept the first number else the previous calculation result
will be the first number.
if(flag == new_cal)
{
cout << "Enter first number:";
cin >> num1;
}
else
{
num1=temp;
cout << "\nFirst number is:" << num1 <<endl;
}
cout << "\nEnter second number:";
cin >> num2;
temp = num3;
flag = old_cal;
break;
case 2:
if(flag == new_cal)
{
cout << "Enter first number:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nFirst number is:" << num1 << endl;
}
cout << "Enter second number:";
cin >> num2;
case 3:
if(flag == new_cal)
{
cout << "Enter first number:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nFirst number is" << num1 << endl;
}
cout << "Enter second number:";
cin >> num2;
temp = num3;
flag = old_cal;
break;
case 4:
if(flag == new_cal)
{
cout << "Enter first number:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nFirst number is" << num1 << endl;
}
cout << "Enter second number:";
cin >> num2;
num3 = stand_calc :: division(num1 , &num2);
cout << "\nDivision of " << num1 << " by " << num2 << " is " << num3;
temp = num3;
flag = old_cal;
break;
case 5:
if(flag == new_cal)
{
cout << "Enter first number:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nFirst number is" << num1 << endl;
}
cout << "Enter second number:";
cin >> num2;
num3=stand_calc::modulu(&num1 , &num2);
cout << "\nModulus of " << num1 << " by " << num2 << " is " << num3;
temp = num3;
flag = old_cal;
break;
case 6:
cout << "\nReturning to previous menu.";
cout << "\nPress any key to continue......";
break;
case 7:
cout << "\nQuiting..........";
cout << "\nPress any key to continue......";
exit(0);
case 8:
//If a new calculation is going on then option 8 is an invalid option, else 8 is an option to start a
new calculation.
if(flag == new_cal)
{
cout << "\nInvalid choice.";
cout << "\nPress any key to continue......";
}
else
{
temp = 0;
flag = new_cal;
}
break;
default:
cout << "\nInvalid Choice.";
cout << "\nPress any key to continue......";
break;
}
} while(choice2!=6);
break;
case 2:
// Loop to display the scientific calculator menu.
{
do
{
if(flag == old_cal)
cout << "\n10\tClear Memory";
cout << "\nChoose the type of calculation:";
cin >> choice2;
switch(choice2)
{
case 1:
if(flag == new_cal)
{
cout << "Enter number to find square:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nNumber is" << num1 << endl;
temp = num3;
flag = old_cal;
break;
case 2:
if(flag == new_cal)
{
cout << "Enter number to find cube:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nNumber is" << num1 << endl;
temp = num3;
flag = old_cal;
break;
case 3:
{
if(flag == new_cal)
{
cout << "Enter first number for base to find power:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nFirst number is:" << num1 << endl;
}
cout << "Enter second number for power to find power:";
cin >> num2;
temp = num3;
flag = old_cal;
}
break;
case 4:
{
if(flag == new_cal)
{
}
else
{
num1 = temp;
cout << "\nNumber to find factorial is " << num1 << endl;
temp = num4;
flag = old_cal;
}
break;
case 5:
{
if(flag == new_cal)
{
cout << "Enter number to find sin value:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nNumber for sin value is:" << num1 << endl;
temp = num3;
flag = old_cal;
}
break;
case 6:
{
if(flag == new_cal)
{
cout << "Enter number to find cos value:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nNumber for cos value is:" << num1 << endl;
case 7:
{
if(flag == new_cal)
{
cout << "Enter number to find tan value:";
cin >> num1;
}
else
{
num1 = temp;
cout << "\nNumber for tan value is:" << num1 << endl;
case 8:
{
cout << "\nReturning to previous menu.";
cout << "\nPress any key to continue.......";
getchar();
}
break;
case 9:
{
cout << "\nQuitting..........";
cout << "\nPress any key to continue.......";
getchar();
exit(0);
}
break;
case 10:
{
if(flag == new_cal)
{
cout << "\nInvalid choice.";
cout << "\nPress any key to continue.......";
getchar();
}
else
{
temp = 0;
flag = new_cal;
}
}
break;
default:
{
cout << "\nInvalid choice.";
cout << "\nPress any key to continue.......";
}
break;
}
} while(choice2!=8);
}
break;
case 3:
{
cout << "\nQuitting.......";
cout << "\nPress any key to continue.......";
}
break;
default:
{
cout << "\nInvalid choice.";
Standard Calculator
In the above test case, a standard calculator has been used taking an example of
modulus calculation. The user is asked to input the first number and then the second number
and thereafter satisfying the conditions the result is provided.
After the calculations have been completed, the user is asked multiple choices such as
returning to the previous menu which takes back the user to select the calculator type while
storing the previous result, if the user opts to clear the memory then the previous result isn't
saved and therefore will not be a part of any further calculations.
Here the user asks to quit the calculator and hence the program terminates.
Scientific Calculator
In the above test case, a scientific calculator has been used taking an example of factorial
calculation. Similarly, the user is asked to give the input for the further calculations, and
thereafter the result is successfully provided.
The menu is again called for further actions while it stores the value from the previous
result. In this case, the user asks for the square and hence the calculations are performed on
the value stored as the user didn’t clear the memory.
In the end, the user asks to quit the calculator and hence the program terminates.
6. Conclusion:
The program is running successfully and hence the calculator is working appropriately fulling
its objectives with all the required features.
REFERENCES
● Object-Oriented Programming with C++ by E. Balagurusamy
● www.draw.io for making class diagrams