sample.cpp modified