Friday 18 September 2020

Chapter 16 // Exercise 9 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and modified versions of the graphics files used throughout the chapters. You can find those versions through the link below.

Chapter 16 // Exercise 9

Modify the calculator from Chapter 7 to get its input from an input box and return its results in an output box.

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2016/Exercise%209

Oh I wish this chapter would stop haunting me. Looking at the code though reminds me of how eager I was to put in error messages. Now I just don't care.

I also wanted to avoid messing with get() and unget() as much as possible so I googled how to put a string into cin and found this very handy section of code:

This uses istringstreams and effectively "fakes" typing in the keyboard. The calculator code thinks we've typed into cin and will happily go about getting and putting back characters in cin.

I did remove a few functions and moved definitions into a cpp file (with declarations in the header) but for the most part it has stayed intact from the code uploaded here:

You can both type statements into the calculator (just don't type '=' press the button) and press the buttons:

Chapter 16 // Exercise 9 - Principles & Practice Using C++




No comments:

Post a Comment