C++ :: Programming challenge of sorting data by some prerequisites