hackerrank virtual functions problem solution in c++ programming