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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <string>
#include <math.h>

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.