Pages

Tuesday, 25 May 2021

Chapter 20 // Exercise 3 - Principles & Practice Using C++

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

Chapter 20 // Exercise 3

Look at the palindrome examples (section 18.7); redo the Jack-and-Jill example from section 20.1.2 using that variety of techniques.


The wording of this confused me as those palindrome examples are about palindromes; i.e., words that are the same backwards and forwards; what has that got to do with reading in doubles?

But I stared at section 18.7.1 and realised at the heart it's just comparing two things which is what high is doing. So I re-did high to compare using the techniques from the string, array and pointer examples.

The "string" one was a bit tricky to adapt as there's really no point in going backwards unless I'm comparing two, then comparing again against the current high.

The array one was simple enough and I could use indexing which is always nice. Also, you don't need to change Jill's data into an array as a vector is basically an array; you just give it the address of the first element and the size.

I didn't do the pointer one because I had already done that in exercise 2.

No comments:

Post a Comment