### GUI Calculator

I'm new to programming and joined a class at a local college, I'm only looking to see how to work this out. I am completly new to programming, and the teacher threw this assignment at us pretty fast and I feel I dont understand it enough to even know how to work it out.

Provide a graphical user interface for a calculator using Dr. Stroustrup’s code in the textbook as the base

1. Consider the following menu buttons (free design):
• decimal digits (0, . . . ,9) and decimal dot (.)
• parentheses (left ( and right ) )
• change sign (±) to change sign from + to − and from − to +in the displayed number
• four arithmetic operators (+,−,,/)
• percentage of a number (%) which is equivalent to dividing the number by 100
• square root (p or SQRT)
• exponentiation (ˆ) which takes a number to a power (example: 2.1ˆ3.2). Note that bpq = b(pq).
• result (=) to display a result
• clear (CR) to clear the display
• exit/quit (OFF) to exit from the program

2. All computations should be done using type double. Every number is treated as a floating-point decimal number
(even if it was entered without a floating-point dot).

3. If an operation cannot be handled, display the word “Error” (as in the division by 0, or calculating p−1)

4. The display should be implemented as an out_box.

5. You should not use any in_boxes. To enter numbers you use digit buttons, possibly with a decimal dot.
Here's a calculator that I have done that might help you with some calcualtions you want to do, but I don't have a GUI. (Sorry if its a bit long)
FYI I'm still a beginner but I thought this might help you
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173`` ``````#include #include #include using namespace std; int main() { double num1; //An integer that the user will enter double num2; int numForRadian = 180; double pi, radius, area, circum, diam; //declaring the numbers the user will enter for the radius, area, etc. pi = 3.141592653589793238462643383279502884197169399375; //defining PI string userInput; //A variable needed for input into the program float base, power, total; //declaring the numbers need for indexing float radian; int angle; double percentage; char mathOp; //char variable for math operators i.e "+", "*" etc float sum; //float variable for the total of the two numbers the user enters do{ //Do while loop to loop through the program cout << "Please choose a Calculation you want to do: \nAddition - 1 \nMultiplication - 2 \nSubtraction - 3 \nDivison - 4 \nPower - 5 \nSquare Root - 6 " << endl; cout << "Cirlce Calculations - 7 \nDegree to Radian - 8 \nPercentage - 9" << endl; cin >> userInput; if(userInput == "1") //if statement for addition if user enters 1 { cout << "You chose Addition!" << endl; cout << "Enter your calculation: " << endl; cin >> num1; //inputting integer cin >> mathOp;//inputting operator cin >> num2; switch(mathOp) { case '+' : sum = num1 + num2; //if user enters 4+3 it will add break; } cout << "= " << sum; //printing out the total of the numbers entered }else if(userInput == "2")//same as last one just multiplies { cout << "\t* - Multiply" << endl; cout << "You chose Multiplication!" << endl; cout << "Enter your calculation: " << endl; cin >> num1; cin >> mathOp; cin >> num2; switch(mathOp) { case '*' : sum = num1 * num2; break; } cout << "= " << sum; }else if(userInput == "3")//subtract calculation { cout << "You chose Subtraction!" << endl; cout << "Enter your calculation: " << endl; cin >> num1; cin >> mathOp; cin >> num2; switch(mathOp) { case '-' : sum = num1 - num2; break; } cout << "= " << sum; }else if(userInput == "4")//division calculation { cout << "\t/ - Division" << endl; cout << "You chose Division!" << endl; cout << "Enter your calculation: " << endl; cin >> num1; cin >> mathOp; cin >> num2; switch(mathOp) { case '/' : sum = num1 / num2; break; } cout << "= " << sum; }else if(userInput == "5")//power calculation { cout << "You chose to Index your number!" << endl; cout << "Please enter your base number: "; cin >> base; //inputting the base number to index cout << "Please enter the power: "; cin >> power; //inputting the power total = pow(base, power); //calcualte the base and power e.g 5^3 cout << base << " to the power of " << power << " = " << total << endl; //prints out the total } else if(userInput == "6")///sqaure root calculation { cout << "You chose Square root!" << endl; cout << "Please enter the number you want to Sqaure Root: "; cin >> num1; //entering a number to sqrt cout << "The sqaure root of " << num1 << " = " << sqrt(num1) << endl; //simple code to sqaure root the number }else if(userInput == "7")//cirlce calculation { cout << "You chose Cirlce Calculations!" << endl; cout << "\nWhat do you want to calcualte?" << endl; cout << "Area - 1" << endl; cout << "Circumfrence - 2" << endl; cin >> userInput; if(userInput == "1")//if user enters 1 it will go to the area calculation { cout << "Please input value of radius for the area: " << endl; cin >> radius;//inputting radius area = pi * (radius*radius); //calculating area e.g Pi*r^2 cout << "The area of the cirlce is " << area << endl;//outputting area } else if(userInput == "2")//if user enters 2 it will calcualte circumfrence { cout << "Please input the diameter of the cirlce for the circumfrence: " << endl; cin >> diam;//inputting diameter circum = pi * diam;//calculating circumfrence e.g Pi*d cout << "The circumfrence is " << circum;//outputting cirumfrence } }else if(userInput == "8") { cout << "You chose to convert degrees to radians!" << endl; cout << "Enter your angle: " << endl; cin >> angle; radian = (pi / numForRadian) * angle; cout << angle << " degrees in radian is " << radian; } else if (userInput == "9") { cout << "You chose Percentage!" << endl; cout << "Enter your calculation: " << endl; cin >> num1; cin >> mathOp; cin >> num2; switch(mathOp) { case '/' : percentage = num1 / num2 * 100; break; default: cout << "Error - Invalid Input!"; } cout << "= " << percentage << endl; } cout << "\nWould you like to do another operation? (y/n)" << endl; cin >> userInput; }while(userInput == "y");//if user enters "y" it will loop the program again }``````
Topic archived. No new replies allowed.