Your SlideShare is downloading. ×
0
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Ch03
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ch03

668

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
668
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Chapter 9 Calculator
  • 2. Chapter Objectives <ul><li>Provide a case study example from problem statement through implementation </li></ul><ul><li>Demonstrate how a stack and a list can be used to solve a problem </li></ul>
  • 3. A Calculator <ul><li>A calculator is a simple utility that is provided with most operating systems </li></ul><ul><li>A calculator provides </li></ul><ul><ul><li>a keypad of integer digits, </li></ul></ul><ul><ul><li>the associated operations, </li></ul></ul><ul><ul><li>other useful characters such as parentheses and brackets </li></ul></ul>
  • 4. A Calculator <ul><li>For this case study, we will create a graphical calculator that: </li></ul><ul><ul><li>accepts an infix expression, </li></ul></ul><ul><ul><li>converts that expression to postfix, </li></ul></ul><ul><ul><li>evaluates the postfix expression, </li></ul></ul><ul><ul><li>returns the result </li></ul></ul>
  • 5. A Calculator <ul><li>Our infix expressions may include </li></ul><ul><ul><li>Integers </li></ul></ul><ul><ul><li>Basic arithmetic operators </li></ul></ul><ul><ul><ul><li>addition, subtraction, multiplication, division </li></ul></ul></ul><ul><ul><li>Parentheses </li></ul></ul><ul><li>All of the tokens in our expression must be separated by a space </li></ul>
  • 6. A Calculator <ul><li>Our graphical user interface will allow the user to click on the numeric digits or simply press the numbers (and other characters) on the keyboard </li></ul><ul><li>The user will click the equals button to start the evaluation of the given expression </li></ul>
  • 7. A Calculator - Initial Design <ul><li>A calculator consists of four high-level components: </li></ul><ul><ul><li>The driver </li></ul></ul><ul><ul><li>The graphical user interface </li></ul></ul><ul><ul><li>The infix to postfix converter </li></ul></ul><ul><ul><li>The postfix evaluator </li></ul></ul>
  • 8. A Calculator - Initial Design <ul><li>Unlike the BlackJack case study, these high-level components are virtually unrelated, and we are not yet aware of any low-level components that will be needed </li></ul><ul><li>Thus this problem lends itself to a top-down approach to design </li></ul>
  • 9. A Calculator - the CalculatorDemo Class <ul><li>The CalculatorDemo class will serve as the driver for our system </li></ul><ul><li>This class will simply instantiate the GUI and call its display method </li></ul>
  • 10. A Calculator - the CalculatorGUI Class <ul><li>Other than the driver, the GUI is the highest-level component in this system </li></ul><ul><li>The GUI must provide buttons to represent the digits, the operations, parentheses, and an equals button </li></ul>
  • 11. FIGURE 9.1 The calculator user interface
  • 12. A Calculator - the infixToPostfix Class <ul><li>The purpose of the infixToPostfix class to to provide a conversion method that accepts an infix expression as a string and returns the equivalent postfix expression </li></ul><ul><li>Since we know that the postfix expression will then be evaluated,we will return the postfix expression as an unordered list rather than a string </li></ul>
  • 13. &nbsp;
  • 14. A Calculator - the listPostfixEvaluator Class <ul><li>Like our example from Chapter 6, the listPostfixEvaluator class will take the postfix expression and use a stack to evaluate it </li></ul><ul><li>The difference from our earlier example is that the expression has already been broken into tokens by the infixToPostfix class </li></ul>
  • 15. A Calculator - the listPostfixEvaluator Class
  • 16. FIGURE 9.2 UML description of the initial design of a calculator

×