Monday, 13 February 2023

Chapter 26 // Drill 4 - Principles & Practice Using C++

In this exercise I'm using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 26 // Drill 4
Repeat these tests for sequences of strings, such as { Bohr Darwin Einstein Lavoisier Newton Turing }.

Instead of writing out the tests myself (or getting a load of random strings and writing them out to a file), I googled " how to make random string" and used this code to create a randString() to go with randint().

They're garbled messes but whatever. I then made the original Test struct templated so the value could be any type. This required making all the functions using Test to also be templated. 

I also had to slightly change the istream operator >> as now we're reading in strings, reading '}' into a string won't cause the input stream to fail (as it's a valid character for a string). So, in that case, I put the character back into the stream and continue.

Along with the random tests, I made a small test file to see some working examples. Doing this showed me I forgot to sort the container of sequences before doing the binary search....

No comments:

Post a Comment