12

So, my take on this is to sit down with the student and have roughly this talk: So, I'm a little disappointed by the lab you handed in, for two reasons. The first is that it is pushing on the edges of plagiarism. Now, I'm not going to go through the formal process, and there is going to be no punishment this time. I am instead assuming that this is a ...


8

I would teach the use of arrays and array indices first (with pictures of a long row of physical mailboxes, or school lockers, etc.) Then later explain that all of a computer's and/or C program's (process) memory can be thought of as one big array with a pointer being a form of index (locker number) into that (virtual) memory array. You can then draw a ...


6

What you have there is an excellent start, and is completely appropriate. I would go next into a puzzle to try to get them hooked. I would type the following code in front of them on your projector, and ask them to pair with a neighbor to try to figure out what will happen next. (Note, for this to work properly, you must turn off stack security in gcc, ...


6

My advice to all of these problems is the same. Your students do not know how to draw out memory. This is a basic technique that most people who have been programming for a while do mentally, but that nearly all students need to be explicitly taught and shown on paper. How to Draw Memory There is a good chance that you have seen something like this before....


6

If I'm interpreting your question correctly you'd like real life examples that translate to code. Maybe something like the following. You want to drive or ride your bike to the ice-cream shop a few miles away. You don't know how far it is exactly but you will recognize it when you get there (while), VS You want to ride your bike 15 miles out and then ...


4

Yours is a fine first lesson, although it does not show the value of pointers. I would suggest also demonstrating how pointers can be used to implement a swap function. Ask the students (or step them through) what this code does: void swap(int x, int y) { int temp = x; x = y; y = temp; } int main() { int a = 1; int b = 2; printf("...


4

Obviously, beginners in C will have to deal with addresses and pointers really soon. First, you owe them an explanation about addresses for int aNumber; scanf ("%d", & aNumber); // an address printf("%s", aNumber); // a value which will appear in your first examples. So the "address of" operator is known from the ...


4

I would use more visual examples that target conceptual knowledge first. I would do a TON of memory diagrams with code tracing. Then, introduce the idea of pointers as memory addresses like you do in your example. I am a big fan of Nick Parlante's pointer materials. I know they are vintage at this point, but I haven't found anything better at explaining ...


4

It sounds like the program of study has a few bugs if 4th or 5th year students cannot reason about a loop. I taught myself programming in 9th grade by writing simple programs that printed shapes on the screen using characters. For example, make a solid rectangle. Now modify the program to make it a hollow rectangle. Accept input to get the width and height, ...


4

I recognize the feeling of despair! However, I don't think that you want what you are asking for. The most shocking bit of code that I know to show students is the code I wrote up here. Beware, it's quite strange! If you want a bit of fun, don't look at my explanations. Just copy the code into an IDE, look it over, make a guess about what it will do, ...


4

I recently used default arguments to write an API method for a mail sending library: The method needs a subject, a body and a "To" recipient, "Cc" and "Bcc" are optional: def send(subject, body, to, cc=None, bcc=None): """ Send a message with the given data using the earlier configured SMTP server and the ...


4

Probably the most basic example is Python's print function, which has keyword arguments sep and end.


3

I like TuringTux's answer quite a lot. If you're looking for a simpler example for the classroom just to illustrate, you might consider printing an array with an optional delimiter. public void printArray(IList<T> array, string delimiter = ", ") { foreach (T in array) { Console.Write(T + delimiter); } Console....


3

I don't have a good answer to this. However here are my thoughts. Named constructors A good use for static factory, is to implement named constructors: Java, C#, C++, et al do not have named constructors. However named constructors can be useful, as they allow you to document different ways of constructing an object. Therefore use a static factory, to create ...


3

Not sure you can blame the learner really. If the information was obtained by RingTFM then full marks. Hacking the standard library - unconventional but shows initiative. The real problem was the assignment wasn't it? You say that the answer was literally written in the manual, that the standard library had a routine for it...hmm. Now there is a real danger ...


3

I think you have a misunderstanding about something, but I can't say precisely what. You seem to really be asking for two different sorts of CT, not CT vs something else. Both math and CS require some facility in CT and, thus, CT is a prerequisite, whether taught explicitly or learned on one's own. So, if a student can provide a "trivial" solution to a ...


2

My go-to for programming patterns these days are games, because it is easy to create compelling examples. It has never occurred to me before to have a factory return its own subclass, so I apologise if I turn out to be off the mark here! However, the use I immediately thought of was an enemy factory that only provides instances of its subclasses, randomly (...


2

I would first ask what that hierarchy buys you overall in an application and, more important, in the student understanding. In general, I find concrete subclassing to be problematic and easily abused, as well as confusing. If you are satisfied that it is essential in some way, then an example could involve the characteristics of some figures coming from a ...


2

I'm not aware of any singular, central repository for assignment ideas. My sources for project ideas when my own well begin to run dry are: Textbooks. Often, a problem in a problem set will trigger an idea for a full-blown lab assignment. Other similar courses posted by other professors. Obviously, it is important not to simply steal someone's idea. I ...


1

I think it was in some Python tutorial I read ages ago, but at the very beginning, in bold, there was a statement (paraphrasing from memory): Whatever you do, do not copy the code. Copying code stops you from learning, from remembering. Rewrite it. Paraphrase it. Do not copy. Perhaps the student who copied that code id not know of this principle? ...


1

Having looked through all the answers thus far the other day, I'm not entirely satisfied with any of them (I'll try to take the time later and go through to leave comments). However, for now, I'll post what I came up with for class. First, I want to emphasize that these students only know what was mentioned above, no arrays/data structures, very little in ...


1

You would know beforehand when the for loop would terminate, this is not clear in a while loop. I basically tell my students "if you know when it ends, it's a for". (Sure, one can construct pathological cases and there is always this for (;;), but for basic understanding this issue is the crucial difference between for and while.) As for examples: print ...


Only top voted, non community-wiki answers of a minimum length are eligible