Problem #36
Solution Source Code
Code Overview
1. Header Files and Namespace:
<iostream>
is included for input and output operations.<string>
is included for handling message prompts.using namespace std;
allows the use of standard functions without prefixing them withstd::
.
2. Enumeration (enOperationType
)
- Defines four possible arithmetic operations:
+
→ Addition-
→ Subtraction*
→ Multiplication/
→ Division
3. User Input Function (ReadNumber
)
- Takes a custom message as input.
- Prompts the user to enter a floating-point number.
- Reads and returns the number.
4. Operation Selection Function (ReadOpType
)
- Prompts the user to enter an operation type.
- Reads a single character (
+
,-
,*
,/
). - Converts and returns it as an
enOperationType
enum.
5. Arithmetic Calculation Function (Calculate
)
- Takes two numbers and an operation type as input.
- Uses a switch statement to perform the selected operation:
- Addition (
+
) - Subtraction (
-
) - Multiplication (
*
) - Division (
/
)
- Addition (
- Returns the computed result.
6. Program Execution (main()
)
- Calls
ReadNumber()
twice to get two input numbers. - Calls
ReadOpType()
to determine the arithmetic operation. - Calls
Calculate()
to compute and print the result. - Returns
0
to indicate successful execution.
This structured explanation ensures clarity and ease of understanding.
0 comments