Add Q2 answer

Please review, thanks!
Also, I tried to fully conform to the style guide, please let me know if there's anything I'm missing.
Can you write here a few test cases for each function? I'm thinking about using gTest for some test but it requires g++. I'll do some research.