add chapter 6 cpp code and improve readability