Thursday, 20 February 2020

Chapter 10 // Exercise 11 - 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 11

 Write a program that produces the sum of all the whitespace separated integers in a text file. For example, bears: 17 elephants 9 end should output 26.


I was going to leave this last exercise for the night but seeing as how it was the last one of the chapter I decided to just get it done and ended up doing it in 5 minutes. This was very easy if you just read everything into a vector, sort it and then convert the string to an int using stoi(). If it's not an int then we've run out of numbers and the program breaks out of the for loop and prints the sum.

It's funny, I remember almost 3 years ago now when I was starting the second semester of my first year at uni and in the programming exam we had coming up, we had to read in from text files and output to them. I froze and started freaking out because I had only done up to around chapter 5 by then. I thought the task was impossible and I'd never be able to do it; that I wasn't good enough or smart enough to be able to remember all these coding conventions. Progress takes time and patience; not all of us are born as geniuses. Just keep working at it and don't give up.

And with that I have FINALLY finished Chapter 10. I originally started this chapter in June 2017 and it's crazy to think I'm just now moving onto a fresh chapter. I remember giving this a read through a few years ago but it's all new content from here on out. I'm excited to start the graphics chapters though and he starts to introduce templates and inheritance. I hate these constructs but I work with Unreal and UE4 loves object oriented programming...and I mean, it really fucking loves it. Personally, I detest OOP but that's what the job requires so I need to understand it better so I can undo it and replace it with faster data orientated code.

No comments:

Post a Comment