implement interpolation code in C++