Thursday, December 29, 2016

Another Chapter Finished

Yes, it is accomplished, another chapters programming challenges are overcome, and a challenge it was indeed. When i started out with challenge 5.01 i was stumped. I felt like i learned nothing at all about loops when it was time to put into practice what i learned about and practiced during this chapter. Slowly things fell into place, and i started to see how to use which loop, and why indeed one is better to use in certain situation than the other, and how loops, and their logic work. Specifically the for loops, which only really become clear to me when it came to the hardest challenge of all, which was displaying patterns of +'s side by side.

Writing the for loop as such to display the patterns was not the problem, but once i saw that formatting the output like this:

cout << " ";

directly under the first two for loops displaying the first pattern, or

cout << "\t ";
cout << setw(12) << right;
...

which ALMOST worked, but had the ill side-effect of intending only the first couple of columns of pattern B to the right, the last two were always way to the left, I was lost. After doing some good hard thinking, and with the solution right in front of my eyes all the time, it dawned on me. Why, if you can use a loop to display both patterns, why not try and add another! And, yes! It worked! I virtually jumped for joy when i figured it out, and it actually worked the way it was supposed to! That was the moment when I felt actually having mastered what i have learned in the chapter by solving all the other challenges before.

One thing i also learned to love in particular, my debugger and how much clearer things become when going through it, setting break-points, and look at which variable gets which value, what actually happens when a number in a loop increments, and what other value then changes. And, back to the pattern display challenge, it became clear as day to me how the loops i have written logically "work together" and in what order. Because, as it is written, it seems counter intuitive seeing that the first two for loops decrement columns and rows, yet displaying +'s all the while.

Looking at it from the perspective of what it does, deducting rows and columns and display only 1 + instead of 10 rows and 10 columns of +'s, or the other way around, just like it would have in the programming challenge previous to the pattern A/B one, is clear. But actually seeing how it actually works, looking at it while running the program through the debugger is a totally different story, yet a very illuminating one, i learned very much from.

Apart from that, there were some programs to write that looked like they are going to be difficult, but almost felt like they wrote themselfs. Difficulties, speaking of which, there were many during the course of solving these challenges. Most didn't even have to-do with writing the code itself, but with the things that are asked for. For instance the Payroll Report, Savings Account Balance, or Student Line Up. Each came with a specific set of challenges that i knew little about. In case of the Payroll Report program, it was i guess not knowing how such a report is calculated, but sites like The Balance or Calculator Soup and Discovery Education among others, helped me in finding the necessary information, or formulae, that would (hopefully) lead to correct results once the programs run. So, the main source of my problems was seldom how to write the program, all the loops etc, but simply a lack of knowledge in certain areas that - as a positive side-effect, greatly increased, though are of little practical value in real life.

The last thing i learned from working on this chapter is that some code might be so much more easy to write, or so much shorter than it actually turned out to be, with knowledge of "tools" i do not yet posses, but will certainly follow in one of the next chapters.

In one of the reviews i read about the book Starting Out with C++ from Control Structures through Objects, someone was complaining that:

"The problems in each chapter can not be solved, just because some concepts haven't been learned."

Yet every challenge can be solved, even though it turns into one long code, as with the Mobile Service Provider challenge, and it is a valuable lesson in itself to realize that:

Even with the most limited set of keywords and programming concepts, one can write dozens and dozens of programs, some of actual practical value! Learn about loops and random number generation for instance, and you can calculate 200 sets of Lottery numbers easily, or write a statistical program, for whatever you need it to do, or your own household account managing software (if only in the console). Or some fun little game to help your child or children learn basic maths with. How about that!    

And then finally, there is stupidity ... Imagine how I read what is asked for in Challenge 5.24, which is all about reading in a set of numbers, calculating the sum, the average number of numbers, and then the sum of all numbers. What is the first thing i did? Guess ... You can't? I opened the text file, and clicked my way through the list, counting it myself to see how many numbers it contains, for getting the correct result once the file is read in and the loop begins to count numbers ... But such things do and will happen once and again, how about the practical value of Wordpad, simply displaying line numbers? Anyone? Which occurred only after having finished counting by hand all the numbers of numbers ... (Which I also, just to be sure that i counted correctly ...) S-T-U-P-I-D!

Anyway, it was a long journey so far, 5 chapters, thousands of lines of code written, dozens of challenges solved, and yet hundreds of pages and challenges in front of me. I totally look forward to overcome every single one, because every challenge mastered is a stepping stone on the way to mastery far ahead, and my goal: Realizing my own game, be it ever so humble.

With this I wish all of my fellow learners success on their path, fun while trying to solve the challenges ahead of you, and that you may be spared from all too numerous occurrences of AAAAAAAAAAARGH! and GRRRRRRRRRRRRR! moments, that probably everyone out there is familiar with.

No comments:

Post a Comment