Pages

Saturday, 21 January 2023

Chapter 26 // Drill 2 - 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 2

Complete a file of tests for the sequences from section 26.3.
a. { 1 2 3 5 8 13 21 }                 // an ordinary sequence
b. { }                                          // an empty sequence
c. { 1 }                                       // just one element
d. { 1 2 3 4 }                             // even number of elements
e. { 1 2 3 4 5}                           // odd number of elements
f. {1 1 1 1 1 1 1  }                     // all elements equal
g. { 0 1 1 1 1 1 1 1 1 1 1 1 }     // different element at beginning
h. { 0 0 0 0 0 0 0 0 0 0 0 0 1 }   // different element at end

The one thing that tripped me up was the for loop in testAll. I forgot to clear the Test struct each time, so it's sequence vector always had the incorrect numbers in it!

Friday, 20 January 2023

Chapter 26 // Drill 1 - 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 1

Get the test of binary_search to run:
Implement the input operator for Test from section 26.3.2.2

This didn't take too long. I love stringstreams and I'm so glad someone on the C++ committee added them to the standard.