How do I go about this in c++?