So let's see the code you have so far. Tell us which part of the code doesn't seem to be working as you wish. If you're stuck on how to do something, enter each of these commands at the shell prompt:
man 3 system
These will be directed to C programmers, but they can be used by C++ programmers as well.