You should show some effort in attempting this problem before asking for help. There's a good C++ tutorial at this site: http://www.cplusplus.com/doc/tutorial/.
peter_budo commented: Question was asked in Java section not C#, so do not post irrelevant stuff -4