Update sample.cpp

sub function added