Wednesday, 19 February 2020

Chapter 10 // Exercise 10 - Principles & Practice Using C++

In this exercise I am using Visual Studio Community 2017 and the header file "std_lib_facilities.h" which can be found here:

http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

Chapter 10 // Exercise 10

         Add a command from x to the calculator from Chapter 7 that makes it take input from a file x. Add a command to y to the calculator that makes it write its output (both standard output and error output) to file y. Write a collection of test cases based on ideas from section 7.3 and use that to test the calculator. Discuss how you would use these commands for testing.


I cheated slightly on this one and modified the calculator to only take input from a file and then output to a file; if there is an error it will ask you to press ';' to continue. This was pretty simple as you can continue to use cin.get() and cin.unget() on ifstreams. If you run the txt file I provided, you'll notice that it just keeps going forever because it gets stuck in a loop on 'a';. This isn't broken, it expects you to input a correct definition however, 'a' keeps getting putback and then being re-read. If I wasn't feeling lazy I would stick a command in that would switch to regular calculator code and allow you to start inputting your own stuff.

No comments:

Post a Comment