Programming Assignment: Mid Term Project A Simple Calculator

$24.99 $18.99

Summary: Write a console program (character based) to do simple calculation (addition, subtraction, multiplication and division) of two numbers using your understanding of control flow, input validations and error conditions in C. Description: You need to write a program that when run will display a menu. The menu gives five choices of operation: addition, subtraction,…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Summary: Write a console program (character based) to do simple calculation (addition, subtraction, multiplication and division) of two numbers using your understanding of control flow, input validations and error conditions in C.

Description: You need to write a program that when run will display a menu. The menu gives five choices of operation: addition, subtraction, multiplication, division and a last choice to exit the program. It then gives a prompt and waits for the user to make a choice of calculation they want to do. Once user selects the operation it will check for valid menu choices (and give an appropriate message if a wrong choice was selected) and then prompts to enter two numbers separated by a space. If the user entered valid numbers it will do the operation desired and then displays the result. If user input is not valid displays an error message and asks for the correct input. At the end of the result, it gives aprompt “Press enter key to continue ….”. Once enter key is pressed,it displays the menu again. Program repeats until user selects a choice to exit.

Sample Run of the program:

Welcome to <John Doe’s> Handy Calculator

  1. Addition

  1. Subtraction

  1. Multiplication

  1. Division

  1. Exit

What would you like to do? 0

That is not a valid choice, please re-­‐enter: k sdfs sfs

That is not a valid choice, please re-­‐enter: 9

That is not a valid choice, please re-­‐enter: 3

Please enter two numbers to multiply, separated by a space: 24.0 4.0

Result of multiplying 24.00 and 4.00 is 96.00.

Press enter key to continue ….

Welcome to <John Doe’>s Handy Calculator

  1. Addition

  1. Subtraction

  1. Multiplication

  1. Division

  1. Exit

What would you like to do? 4

Please enter two numbers to divide separated by a space:2.0 0

You can’t divide by zero, please re-­‐enter both numbers: asasfs asdfasfas f; sf af sfs

Error reading your numbers, please re-­‐enter both numbers: 16.0 4.0

Result of dividing 16.0 by 4.00 is 4.00.

Press enter key to continue ….

Welcome to <John Doe’>s Handy Calculator

  1. Addition

  1. Subtraction

  1. Multiplication

  1. Division

  1. Exit

What would you like to do? 5

Thank you for using <John Doe’>s Handy Calculator

Note:

  1. Replace the <John Doe’s> with your name

  1. Make sure to properly word the output for the choices and result. Meaning, if user selects ‘1’ from menu, the prompt should be for ‘Addition’ not multiplication as shown in the example.

  2. 3, 24.0 4.0 are shown in the example to emphasize that it is entered by the user and not part of the program. Underline and italics are not a requirement

  3. Your program should allow input of integer or decimal numbers. The output should always be in decimals with two decimal digits as precision.

  1. Make sure your program will continue displaying menu after result is shown and user has pressed enter key. Your program will exit only when user selects 5.

  1. If user selects other than 1-­‐5, show a message that they must select between 1 and 5. Give them a chance to re-­‐enter. Continue until a valid number is entered

  1. If they enter invalid values instead of numbers (e.g. strings), provide an error message and give them chances to re-­‐enter. Continue until valid numbers are entered

  1. Make sure to catch divide by zero error. In case of division choice, the second number should not be zero.

Score: Maximum score is 100 and it is divided into following categories:

  1. Program compiles, runs, and provides the correct answers as described above. (70%)

  1. The design is modular and has number of functions doing part of the work. It should have proper data structures and uses descriptive functions and variable names. (20%)

  1. Proper error trappings is implemented (divide by zero traps, wrong inputs), and is adequately commented and formatted. (10%)

Submission requirement: Name of your source file should be JohnDoe_Calculator.c, change the JohnDoe with your first name and last name. Submit your source code file (only .c file) through the UCSC web-­‐portal (as an attachment) prior to due date in assignment section. Do not submit any other file.

Programming Assignment: Mid Term Project A Simple Calculator
$24.99 $18.99