Convert calcmand.c to C++