# CIS4930 Excercise 1 Scientific Calculator Solved

Build a scientific calculator on the command line. The program will display a menu of options which includes several arithmetic operations as well as options to clear the result, display statistics, and exit the program. The project is designed to give students an opportunity to practice looping, type conversion, and data persistence.

Specification

When the program starts it should display a menu, prompt the user to enter a menu option, and read a value:

Current Result: 0.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 1

If an option with operands (1-6) is selected, the program should prompt for and read double precision floating point numbers as follows:

Enter first operand: 89.1

Enter second operand: 42

Once the two operands have been read, the result should be calculated and displayed, along with the menu:

Current Result: 131.1

Calculator Menu

---------------

…

Operational Behavior

This calculator includes multiple behaviors that are unique depending on the input and operation specified; they are detailed in this section. Results should be displayed to default precision except where specified.

Exponentiation

For exponentiation, the first operand should be used as the base and the second as the exponent, i.e.:

If the first operand is 2 and the second is 4… 24 = 16

Logarithm

For logarithms, the first operand should be used as the base and the second as the yield, i.e.:

If the first operand is 2 and the second is 4… log24 = 2

Displaying the Average

As the program progresses, it should store the total of all results of calculation and the number of calculations. Note that this does not include the starting value of 0! The program should display the average of all calculations as follows:

Sum of calculations: 101.3

Number of calculations: 2

Average of calculations: 50.15

Note that the average calculation should show a maximum of two decimal places. The program should immediately prompt the user for the next menu option (without redisplaying the menu).

If no calculations have been performed, this message should be displayed:

Error: no calculations yet to average!

Using Results of Calculation

The program should allow the user to use the previous result in an operation. The user may enter the word “RESULT” in place of an operand; if the user does so, the program should replace this operand with the result of the previous calculation (or zero if this is the first calculation):

Enter first operand: 89.1

Enter second operand: RESULT

NOTE: Your output must match the example output *exactly*.

File: SciCalculator.py

Method: Submit on Canvas

Sample Output

Current Result: 0.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication 4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 7

Error: No calculations yet to average!

Enter Menu Selection: 1

Enter first operand: 0.5

Enter second operand: -2.5

Current Result: -2.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 5

Enter first operand: RESULT

Enter second operand: RESULT

Current Result: 0.25

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 6 Enter first operand: 2

Enter second operand: 0.5

Current Result: -1.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 7

Sum of calculations: -2.75 Number of calculations: 3

Average of calculations: -0.92

Enter Menu Selection: -10

Error: Invalid selection!

Enter Menu Selection: 0

Specification

When the program starts it should display a menu, prompt the user to enter a menu option, and read a value:

Current Result: 0.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 1

If an option with operands (1-6) is selected, the program should prompt for and read double precision floating point numbers as follows:

Enter first operand: 89.1

Enter second operand: 42

Once the two operands have been read, the result should be calculated and displayed, along with the menu:

Current Result: 131.1

Calculator Menu

---------------

…

Operational Behavior

This calculator includes multiple behaviors that are unique depending on the input and operation specified; they are detailed in this section. Results should be displayed to default precision except where specified.

Exponentiation

For exponentiation, the first operand should be used as the base and the second as the exponent, i.e.:

If the first operand is 2 and the second is 4… 24 = 16

Logarithm

For logarithms, the first operand should be used as the base and the second as the yield, i.e.:

If the first operand is 2 and the second is 4… log24 = 2

Displaying the Average

As the program progresses, it should store the total of all results of calculation and the number of calculations. Note that this does not include the starting value of 0! The program should display the average of all calculations as follows:

Sum of calculations: 101.3

Number of calculations: 2

Average of calculations: 50.15

Note that the average calculation should show a maximum of two decimal places. The program should immediately prompt the user for the next menu option (without redisplaying the menu).

If no calculations have been performed, this message should be displayed:

Error: no calculations yet to average!

Using Results of Calculation

The program should allow the user to use the previous result in an operation. The user may enter the word “RESULT” in place of an operand; if the user does so, the program should replace this operand with the result of the previous calculation (or zero if this is the first calculation):

Enter first operand: 89.1

Enter second operand: RESULT

NOTE: Your output must match the example output *exactly*.

File: SciCalculator.py

Method: Submit on Canvas

Sample Output

Current Result: 0.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication 4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 7

Error: No calculations yet to average!

Enter Menu Selection: 1

Enter first operand: 0.5

Enter second operand: -2.5

Current Result: -2.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 5

Enter first operand: RESULT

Enter second operand: RESULT

Current Result: 0.25

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 6 Enter first operand: 2

Enter second operand: 0.5

Current Result: -1.0

Calculator Menu

---------------

0. Exit Program

1. Addition

2. Subtraction

3. Multiplication

4. Division

5. Exponentiation

6. Logarithm

7. Display Average

Enter Menu Selection: 7

Sum of calculations: -2.75 Number of calculations: 3

Average of calculations: -0.92

Enter Menu Selection: -10

Error: Invalid selection!

Enter Menu Selection: 0

Starting from: $25

You'll get 1 file (1.1KB)