Tuesday, 27 October 2020

Chapter 17 // Exercise 13 - Principles & Practice Using C++

 In this exercise I am using Visual Studio 2017 and the std_lib_facilities header provided by Stroustrup.

Chapter 17 // Exercise 13

Modify the Link class from section 17.10.1 to hold a value of a struct God. struct God should have members of type string: name, mythology, vehicle, and weapon. For example, God{"Zeus", "Greek", "", "lightning"} and God{"Odin", "Norse", "Eight-legged flying horse called Sleipner", "Spear and Gungnir"}. Write a print_all() function that lists gods with their attributes one per line. Add a member function add_ordered() that places its new element in its correct lexicographical position. Using the Links with the values of type God, make a list of gods from three mythologies; then move the elements (gods) from that list to three lexicographically ordered lists - one for each mythology.

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2017/Exercise%2013

What in the ever-living christ? I really hated this exercise when I started it. In fact, I procrastinated so much in doing this exercise that I made a slenderman game in Unreal Engine and did the infamous Blender Donut tutorial:

Chapter 17 // Exercise 13  - Principles & Practice Using C++

Anyway, I finally did it and by the end of it, I have to admit, I understood linked lists WAY better than I did before. Don't skip the exercises everyone; they actually work.

Sure, this is not the greatest code ever written but I did it!

No comments:

Post a Comment