I was taught C++ in high school as a first programming language, although it was more like "C+", now that you mention it; we used cout
for writing text to the console and files, but also quite a few C functions (getch()
was my favourite).
I think the most effective (and possibly fun) way of teaching the basics is using a goal-oriented curriculum: start with showing how to output stuff, then keyboard input, then simple file I/O, etc. Progress to a simple text-based game (or the robotics equivalent). Then when they ask, "How do I do X?", you can break down X in terms of examples they've already seen, e.g. "First you'll need to get the input from the user like we did in Z, then..." (obviously it isn't this easy in practice since X will likely be something that they need additional knowledge in order to do, e.g. "3D graphics", but you could still explain how it would work in a high-level way).
Examples you show them will start out as black-box copy-pasted magic, whose mysteries get unravelled as pieces of the programming puzzle are slowly figured out. For example, your students will learn the basics of if
s quite quickly, but they probably won't realize that a boolean expression is not exclusively limited to use within an if
's condition (leading to classic if (blah) return true; else return false;
code).
The subtleties of whether you choose an array or vector as a container will seem irrelevant to the students at first. A vector/array will simply be a way of having lots of variables as one variable, accessible via an index. Stick to one where you can. Pointers won't be understood until later either. That's not to say that you shouldn't explain things; just that you can't explain everything at once, and the stuff you do explain won't be completely absorbed. Humans learn organically, not linearly. I'd been using cout
for a couple years before I properly understood what operator overloading was!
Oh, and don't be afraid of repetition. "This is like the Hello World program we did -- remember how we wrote text to the console?" (no...) "Let's go through it again just to make sure." ... And ask questions! Keep the students engaged with fun examples and lots of interaction.
C++ is a complex language, and no matter what you do, a significant amount of that complexity (and that of the craft of programming in general) will be lost on your students. Everything you show them will be new to them; most of it won't sink in at a deep level of understanding (at least, not right away). How memory works, how the components of a PC interact, what the stack and heap are, pointers, classes, even loops and if-else chains won't be properly understood by the majority. This is OK! They don't have to be understood to be used -- an amazing amount of cool programs can be written with super-ugly 1000-line functions with quintuple-nested redundant if
s and 43 variables named things like x_2r
. The important thing is that the students are constantly learning and improving. Black boxes are fine as long as they become transparent (or at least translucent grey) in the long run. By the end of the course, they might not know what design patters are, but they should be able to look back at the programs they wrote in the first few weeks and cringe at their code. They should understand at a significant level of detail how the first program they wrote actually works (whereas when they wrote it they had no idea). But they won't know everything -- yet.