finished version of the cp.cpp