Question
A simple calculator can perform basic operations such as add, subtract, division and multiplication operations. It reads two integer numbers and display the result of
A simple calculator can perform basic operations such as add, subtract, division and multiplication operations. It reads two integer numbers and display the result of the selected operation. a) Write an Abstract Data Type (ADT) specification to represent the above calculator. Include operations to perform arithmetic operations (addition, subtraction, multiplication and division). Your ADT specification should include the following information: - The operation's description and post condition - The operation's precondition (if any) - The return value of the operation (if any) (10 marks)
Sol07:
Abstract Data Type (ADT) Specification for Simple Calculator:
- Description: Addition operation Precondition: Two integers, a and b, as input Postcondition: Returns the sum of a and b as an integer
- Description: Subtraction operation Precondition: Two integers, a and b, as input Postcondition: Returns the difference between a and b as an integer
- Description: Multiplication operation Precondition: Two integers, a and b, as input Postcondition: Returns the product of a and b as an integer
- Description: Division operation Precondition: Two integers, a and b, as input, where b is not zero Postcondition: Returns the quotient of a and b as an integer
Note: If the precondition is not satisfied (e.g., b is zero for division operation), the calculator should display an error message and prompt the user to enter new inputs.
- Description: Clear operation Precondition: None Postcondition: Clears the current result and any pending operations.
- Description: Memory operation Precondition: None Postcondition: Returns the current result as an integer and stores it in memory.
- Description: Recall operation Precondition: None Postcondition: Returns the value stored in memory as an integer and sets it as the current result.
Note: The clear, memory, and recall operations do not take any input or return any value, but they modify the current state of the calculator.
Overall, the ADT specification for the simple calculator includes four arithmetic operations (addition, subtraction, multiplication, and division) with preconditions, postconditions, and return values, as well as three additional operations for clearing, storing, and recalling results.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started