Questions tagged [code-example]

Questions about using concrete code examples when teaching.

Filter by
Sorted by
Tagged with
8 votes
21 answers

What is a real-world example of a for-loop?

The example of a for-loop offered in introductory texts is often very contrived. For example, we might have: ...
Samuel Muldoon's user avatar
8 votes
5 answers

Simple Pointer Examples in C

Thanks to feedback in this thread, I'm beginning to plan how to integrate a basic introduction to pointers into my unit on arrays. Here's a sample program I just wrote up: ...
Peter's user avatar
  • 9,082
7 votes
7 answers

Example for For vs While Loop (in Java)

I'm looking for a set of concrete examples that illustrates good use cases of using a for vs a while loop for beginners. I feel ...
cryptic_star's user avatar
5 votes
6 answers

Examples of innocent looking faulty code for shock effect

I'm becoming more and more convinced that starting with an imperative attitude is not doing a favor to the students, especially if it's all about scheduling and repeating some ...
user9137's user avatar
  • 424
5 votes
3 answers

What is a real-world (production-code) example of a function having default arguments?

I want to teach students about default function arguments. I have a bad habit of cooking-up contrived examples. To prove that I am not a student cheating on their homework, I shall provide you with ...
Samuel Muldoon's user avatar
3 votes
3 answers

“What do you mean it’s plagiarism? It’s from the docs!”

I present to you two scenarios that are different, but not enough to warrant two questions. Scenario 1: You discover that a student copied some section of the code verbatim from the docs of some ...
JohnnyApplesauce's user avatar
3 votes
3 answers

What's a good example of a static factory method returning instances of subclasses?

One benefit of having a class provide a static factory method rather than public constructors is the method can return an instance of a subclass. For example, if the class ...
Ellen Spertus's user avatar
2 votes
5 answers

What is an example of class inheritance in every-day life which is easy to write in an object-oriented language?

When a student is first learning about class inheritance it is nice to use an example from every-day life. For example, Plastic Cups are ...
Samuel Muldoon's user avatar
2 votes
0 answers

Python Code Sharing Forum

I have recently switch from SmallBasic to Python for my introduction to programming course. I have managed to translate everything from one language to the other... with a single difficulty. Over the ...
codingCat's user avatar
  • 499
1 vote
4 answers

What is a musical application of linked lists?

When teaching computer programming, occasionally students who are interested in music ask instructors for how a double ended queue could be useful in the music industry. What is a "real-world&...
Samuel Muldoon's user avatar
1 vote
1 answer

An example that compares a computational with a non-computational thinking approach

I have to teach CT to Standard 5 students (11 to 13 yrs). To explain the concept, I am trying to explain to them how CT is beneficial in today's world. The way I learn and appreciate things is by ...
gpuguy's user avatar
  • 269
1 vote
1 answer

Coding assignments for algorithms and data structures?

Do you know of any online resource with ideas/projects for an Algorithms and Data Structures course? Topics in the course include: basic data structures (array, list, stack, queue, priority queue, ...
Drimades Boy's user avatar
1 vote
2 answers

Help identifying a '90s CYOA-style book with BASIC code listings

Way back in the '90s, I read a choose-your-own-adventure style book, where most sections ended in a choice of 2 or 3 different pages to turn to (as is typical). However, this particular book was ...
bguiz's user avatar
  • 111