C++ and function pointers assessment: lack of inspiration
- by OlivierDofus
I've got an assessment to give to my students.
It's about C++ and function pointers.
Their skill is middle: it the first year of a programming school after bachelor.
To give you something precise, here's a sample of a solution of one of 3 exercices they had to do in 30 minutes (the question was: "here's a version of a code that could be written with function pointers, write down the same thing but with function pointers"):
typedef void (*fcPtr) (istream &);
fcPtr ArrayFct [] = { Delete , Insert, Swap, Move };
void HandleCmd (const string && Cmd)
{
string AvalaibleCommands ("DISM");
string::size_type Pos;
istringstream Flux (Cmd);
char CodeOp;
Flux >> CodeOp;
Pos = AvalaibleCommands.find (toupper (CodeOp));
if (Pos != string::npos) {
ArrayFct [Pos](Flux);
}
}
Any idea where I could find some inspiration?
Some of the students have understood the principles, even though it's very hard for them to write C++ code. I know them, I know they're clever, and I'm pretty sure they should be very good project managers. So, writing C++ code is not that important after all. Understanding is the most important part (IMHO).
I'm wondering about maybe break the habits, and give half of the questions about the principle, or even better, give some sample in other language and ask them why it's better to use function pointers instead of classical programming (usually a big switch case).
Any idea where I could look? Find some inspiration?