Simulate a simple four function calculator without a memory

Assignment Help Computer Engineering
Reference no: EM132213280

Question :

Write a Ruby Script that simulates a simple four function calculator without a memory. The operations you should implement are:

+ - Add

- - Subtract

/ - Divide

* - Multiply

Q - Quit Program Error message must be displayed when invalid command is used or attempt to divide by zero. Use a single character as the command for each operation.

Here's a sample of the calculator in use:

Enter First Operand: 0

Enter Command (+ - * / C Q): +

Enter Second Operand : 12

Result = 12

Enter First Operand: -4

Enter Command (+ - * / C Q): -

Enter Second Operand : 12

Result = -16

Enter First Operand: 10

Enter Command (+ - * / C Q): *

Enter Second Operand : 5

Result = 50

Enter First Operand: 13

Enter Command (+ - * / C Q): /

Enter Second Operand : 3

Result = 4.333333

Enter First Operand: 13

Enter Command (+ - * / C Q): \

Enter Second Operand : 3

******* ERROR : \ is not a valid command *******

Enter First Operand: 28

Enter Command (+ - * / C Q): /

Enter Second Operand : 0

******* ERROR : Cannot divide by zero *******

Enter First Operand: 15

Command (+ - * / C Q) Q

End

Reference no: EM132213280

Questions Cloud

Compute morgans dependent tax credit : Morgan (age 45) is single and provides more than 50% of the support of Rosalyn (a family friend, age 36), Flo (a niece, age 18), and Jerold (a nephew, age 18).
Write a regular expression that describes the language : Write a regular expression that describes the following language: the set of strings that that contain an even number of a's.
Write a routine to list out the nodes of a binary tree : Write a routine to list out the nodes of a binary tree in level-order. List the root, then nodes at depth 1, followed by nodes at depth 2, and so on.
Write a recursive function that will take a nonnegative int : Write a recursive function that will take a nonnegative integer n as formal parameter and return its factorial. Trace the function calls for n = 4.
Simulate a simple four function calculator without a memory : Write a Ruby Script that simulates a simple four function calculator without a memory.
Write a regular expression to pass to grep to determine : Write a regular expression to pass to grep to determine if a Chicago area (773 or 312) phone number, in the form (312) 281-3303, is present in a given file.
Write a research about the importance of servers rooms : Write a research about the importance of servers rooms or (network devices rooms) in any organization or institutions.
Write a recursive method search stack which returns true : Write a recursive method search Stack(LinkedStack S, E x) which returns true if the stack S contains the element x, otherwise it returns false.
Compute the value of an expression in parentheses : Write a recursive MARS program that can compute the value of an expression in parentheses.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Developing an algorithm to read an arbitrary number

Develop an algorithm to read an arbitrary number of the data records, each consisting of an age, name, and code.

  What are the two important results of operating system

What are the two important results of operating system management related to the processor and other computer hardware?

  How many different cards can there be

If no column can have more than 2 holes, how many different cards can there be?

  Create a class called person including first name

Create a class called person including first name and last name as string and idnum as an integer. The class should contain a default constructor setting.

  Explain why is normalization essential in floating-point

use apa format to answer the following questionsq1. name five types of data that a computer can process.q2.

  Implementing the soubly linked list adt

Develop, implement, and test the soubly linked list ADT, utilizing the DLLNode objects as the nodes. Additionally to our standard list operations, your class must offer for backward iteration through the list.

  Define how referential integrity actions can be used

explain the default rules for enforcing referential integrity constraints. Explain how referential integrity actions can be used to override the default referential integrity constraints.

  Compare by using exception handling for input data

compare using exception handling for input data validation with using if and switch statements. when would you use each

  Explain why it is important to address these risks

Explain why it is important to address these risks while developing a new system

  Calculate the new pay and write to an output file

Calculate the new pay and write to an output file with employee name and new salary. Format the numbers to display 2 decimal places.

  Create an accordion control for a faq page about rummage

Create an accordion control for a FAQ page about rummage sales. Each content area should provide information about rummage sales, and garage sales.

  Comapre the organizing function of management

Evaluate the organizing function of management as it relates to at least two of the following organizational resources.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd