Talk:C++ Programming/Exercises/Static arrays/Pages

Exercise 7
Is it really a good idea to encourage readers to implement their own sorting algorithm, without a discussion of why this is a bad idea in general? If the aim is to build the reader's understanding of static arrays, rather than to teach Algorithms 101, perhaps it would be better to specify a sorting algorithm in pseudocode. --Fishpi (discuss • contribs) 17:16, 15 February 2011 (UTC)


 * Isn't it covered on the theory side of the book ? If not you can add that information, you can also like to a Wikibook on algorithms or the Wikipedia page (but I thing it may have a solution included). Probably looking into the STL implementation (add the required information on the algorithm and link to that section) this would address all your issues... --Panic (discuss • contribs) 22:57, 16 November 2011 (UTC)

Exercise 7 mistakes
It has been a long time without programming, and actually this is the first time I find myself programming in C++ (for teaching a friend), but I think there are some mistakes on the sorting exercise (1st selection algorithm and bubble sorting). I had to change one of the operators in the second "for". I've replaced the << by < in order to avoid a segmentation fault. At the moment I am not 100% sure of what << does, but I am quite sure that its functionality is not what is needed there.

On the other hand, there were two lines in the 2nd selection algorithm that wouldn't work with my compiler (g++ on linux). These are:

system("pause"); fflush(stdin);

Both things are lines of code stated as to be avoid in C/C++ programming as you can check easily running a quick search on any searching engine. I don't see the need of pausing the program before exiting (and not at all using a function that is not C/C++ standard but a function of the OS, so not portable). And the fflush one, as you can check on the Internet, is absolutely pointless.

Obviously I might be wrong making any of these points, but at the moment I am quite sure they are all mistakes.

What do you think?

Thanks for the wiki anyway. It is being quite helpful for me :-)

Vicisbue (discuss • contribs) 21:30, 16 November 2011 (UTC)


 * The system("pause") would disqualify the proposed solution. I have to look at the example, so I'm talking without looking (I will give it a closer look as I have time) fflush(stdin) may be necessary if the code uses the stdin to read the input since the pause requires a return (it would cause issues in a loop). I would appreciate if you moved that non compilable solution to a new section to be fixed (see the top of the exercises as example). You do not need to give clues to the problems and/or you could yourself take to the job of fixing it as an exercise :) . The << is explained in the theory section of the book.
 * As you go through the exercises do the same for others you find that do not compile, take the right input or give the proper solution. Thanks for the help. --Panic (discuss • contribs) 22:54, 16 November 2011 (UTC)