Teaching Purposes: Converting Java equivalent logic to C++