HTW Berlin Medieninformatik

HTW Berlin
Fachbereich 4
Internationaler Bachelor Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Summer Term 2023


Exercise 8: Fun with Calculators 2

Finger Exercises

Please think through the following questions before coming to the lab. Write down your answers and bring them with you for check-in.

  1. Make sure that your infixToPostfix and evaluatePostfix methods from exercise 6 are in working order! If not, ask to use one from another group. Re-use is good, if you give proper credit in your report.

Lab exercises:

  1. Make a copy of one of your Calculators. Make sure that it works before you begin! If neither of you got a Calculator to work, ask colleagues for permission to use theirs. Give them credit in your report!
  2. Rework it to accept a long String of single digits separated by operators that have precedence. The bored may use multi-digit numbers and floating-point or scientific notation, if they please.
  3. Once you get a String input, add in calls to convert this expression to postfix and evaluate the postfix when = is pressed. Presto, your calculator now takes care of operator priorities, like magic! Just a little bit of mathematical thought, and you can introduce new functionality!
  4. What will be good test cases for the precedence of * over +? Find 15 good test cases and try them out, documenting the results.
  5. Check that this still works with hexadecimal numbers.

For the bored:

  1. Now include the exponentiation operator ^ (2^4 = 16). It has a higher priority than either multiplication or division.
  2. Extend your integer calculator to do multi-digit and doubles.
  3. Extend your calculator to calculate the factorial (!). What do you have to change in your algorithm?
  4. Make your calculator usable for blind people - have your calculator read aloud the button pressed.
  5. How can you make the calculator read the result for blind users in German? In English?

 

Your report is due by 10.00 pm the evening before your next lab! As in Informatics 1, we are more interested in process than in product, although we are now getting more interested in products as well. Your report should include any collaborators, summarize what you learned, and note the time you invested in this exercise. How many lines of code did you write for each exercise? Record this in your report.


Copyright Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty