Convert calcfrac.c to C++