modified homework6.cc