Question: Need a simple GUI for scientific calculator code C++ data strucs algorithms. Doesnt have to be fancy: Thanks #include #include #include //ProtoTypes void arithemeticOpr(); void

Need a simple GUI for scientific calculator code C++ data strucs algorithms. Doesnt have to be fancy: Thanks

#include #include #include //ProtoTypes void arithemeticOpr();

void addition(); void subtraction(); void multipilication(); void division();

void trigonometricFun();

void sinFun(); void cosFunction(); void tanFunction();

void logarithmicFun();

void natural(); void log();

void powerFun();

void power(); void squareRoot();

using namespace std; //The main function int main() { //Charecter type variables to store char letter;

//To print the header cout << " ***************** SCIENTIFIC CALCULATOR ****************** "; //The do while loop to reapt the program untill user enter exit do { //display the menu cout << "\t 1 : Arithmetic Operations "; cout << "\t 2 : Trigonometric Functions "; cout << "\t 3 : Logarithmic Functions "; cout << "\t 4 : Power Functions "; cout << "\t 5 : Exit... "; //Take the input choice cin >> letter; //The swich loop to process various choices switch (letter) { //If user select to perform Arithmetic Operations case '1': { // call the arithemeticOpr function arithemeticOpr(); break; } // end of case 1 arithmatic operation

//if user selects Trigonometric Functions case '2': { // call the trigonometricFun function trigonometricFun(); break; } // inner case 2 trignomatic //if user selects Logarithmic Functions case '3': { // call the logarithmicFun function logarithmicFun(); break; } // end of case 3 logrithmic //if user selects power operations case '4': { // call the powerFun function powerFun(); break; } // end of case power function } // outer switch } while (letter != '5'); //reepat while user not enter 5 return 0; }

void arithemeticOpr() { //Charecter type variables to store char letter1;

//Display the sub menu cout << " "; cout << "\t1 : Addition "; cout << "\t2 : Subtraction "; cout << "\t3 : Multipilication "; cout << "\t4 : Division "; //read the choice cin >> letter1; //the swich loop to process the user selected arithematic operation switch (letter1) { //if user selected to add case '1': { // call addition function addition(); //Break the case break; } //If the user select to subtract case '2': { // call subtraction function subtraction(); //break the case break; } //If user selects multiplication operation case '3': { // call multipilication function multipilication(); //break the case statement break; } //if user selects division operation case '4': { // call division function division(); //break the case break; } } }

void addition() { //To store integer type result int result; //Integer type variables to hold operands int a, b; //Display the message cout << " Enter first number..."; //read the first number cin >> a; //Display the message cout << "Enter an other number..."; //read the first number cin >> b; //Perform the operation and store the result in result result = a + b; //display the result cout << " Result = " << result << endl; } void subtraction() { //To store integer type result int result; //Integer type variables to hold operands int a, b; //Display the message cout << " Enter first number..."; //read the first number cin >> a; //Display the message cout << "Enter an other number..."; //read the second number cin >> b; //perform the subtraction operation result = a - b; //display the result cout << " Result = " << result << endl; } void multipilication() { //To store integer type result int result; //Integer type variables to hold operands int a, b; ////Display the message cout << " Enter first number..."; //read the first number cin >> a; //Display the message cout << "Enter an other number...";

//Display the message cin >> b; //perform the operation and store the result in result result = a * b; //display the result cout << " Result = " << result << endl; } void division() { //To store integer type result int result; //Integer type variables to hold operands int a, b; //Display the message cout << " Enter first number...";

//reaad the first number cin >> a;

//Display the message cout << "Enter an other number...";

//Display the message cin >> b;

//if numerator is not zero //a logical mistake is here actally b!=0 has to be checked //The denominator should not be zero if (a != 0) { //perform the operation and the result is in result result = a / b; //display the result cout << " Result = " << result << endl; } }

void trigonometricFun() { //Charecter type variables to store char letter2;

//diaplay the sub menu cout << " "; cout << "\t1 : Sin function "; cout << "\t2 : Cos function "; cout << "\t3 : Tan function "; //read the choice entered by the user cin >> letter2; //The switch to process various choices switch (letter2) { //If user input 1, that is Sin function case '1': { // call the sin function sinFun(); //break the case break; } //If user input 2, that is Cos function case '2': { // call the cosFunction function cosFunction(); //break the case break; } //If user input 3, that is Tan function case '3': { // call the tanFunction function tanFunction();

//break the case break; } } // inner switch }

void sinFun() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Display the message cout << " Enter a number..."; //read the number from user cin >> a1; //perform the operation, since the result is double store it in result2 result1 = (sin(a1)); //diaply the result cout << " Result = " << result1 << endl; } void cosFunction() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Display the messag cout << " Enter a number..."; //read the number from user cin >> a1; //perform the operation, since the result is double store it in result2 result1 = (cos(a1)); //diaply the result cout << " Result = " << result1 << endl; } void tanFunction() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Display the message cout << " Enter a number..."; //read the number from user cin >> a1; //perform the operation, since the result is double store it in result2 result1 = (tan(a1)); //diaply the result cout << " Result = " << result1 << endl; } void logarithmicFun() { //Charecter type variables to store char letter3;

//Display the inner menu cout << " "; cout << "\t1 : Natural log "; cout << "\t2 : log with base 10 "; //read the user choice cin >> letter3; //Switch to process user choices switch (letter3) {

//if user selects natural log case '1': { // call the natural Function natural(); //break the case break; } //if user selects base 10 log case '2': { // call the log Function log(); //break the case break; } } // end of switch }

void natural() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Display the message cout << " Enter a number..."; //read the input number cin >> a1; //perform the operation result1 = log(a1); //display the result cout << " Result = " << result1 << endl; } void log() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Display the message cout << " Enter a number..."; //read the number from user cin >> a1; //perform the operation result1 = log10(a1); //display the result cout << " Result = " << result1 << endl; }

void powerFun() { char letter4; //diaplay the inner menu cout << "1) Press 1 for Power "; cout << "2) Press 2 for Square root "; cout << "Enter your choice...."; //read the user input cin >> letter4; //The switch to process user choice switch (letter4) { //if user selects power case '1': { // call the power function power(); //break the case break; } //if user selects square root case '2': { // call the squareRoot function squareRoot(); //break the case break; } } // end of switch }

void power() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Display the message cout << " Enter a number...";

//read the first number cin >> a1;

//Display the message cout << "Enter power..."; //read the power cin >> b1; //perform the operation result1 = pow(a1, b1); //display the result cout << " Result = " << result1 << endl; } void squareRoot() { //to store float type result double result1; //Double type variables to hold operands double a1, b1; //Integer type variables to hold operands int a; //Display the message cout << " Enter a number..."; //read the number cin >> a; //find the square root result1 = sqrt(a); //Display the message cout << " Result = " << result1 << endl; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!