Slashdot Mirror


Memorable Programming Assignments?

Albert Schueller asks: "This fall I'll teach introductory programming for the third time. The class is generally populated by students from a wide range of backgrounds and interests-liberal arts and science types. While we use C++, the language isn't really the issue. Rather, the goal is to introduce basic programming ideas like loops, logic, modular programming etc. What are some of your favorite programming assignments that would be appropriate for students at this level?"

19 of 127 comments (clear)

  1. life? by Innomi · · Score: 4, Interesting

    Conway's Game of Life perhaps?

  2. Basic image processing by whee · · Score: 4, Interesting

    One assignment I had gotten in my high school C++ course was a nice introduction to elementary image processing. The design required a simple program that would read a matrix of 1s and 0s from an ASCII text file to perform operations on. A 1 was considered white (on), while 0 was black (off); this part could be expanded to support the full spectrum, although it's good to keep it simple for beginners.

    After loading the 'image', we were required to provide operations that the user could select and perform on the image, such as blob detection, scaling, blurring, etc. (This would be a nice way to introduce modular programming by defining an API for each operation to use and such.) Saving of the image was also supported.

    An assignment such as this would be a great way to bring it all together; matrices, for loops, bounds checking, modular style and others would be covered, showing how all the little things contribute to a larger application.

  3. Mazes and parties by linuxwrangler · · Score: 5, Interesting
    Solving a maze is a good example of recursion.

    Still, my most memorable freshman programming assignment (punch cards/line printer/mainframe no less) was to simulate a cocktail party.

    The party was a two-dimensional array representing the room. At the edge was a door and in the center was the bar.

    You fed the program a list of guests including name, arrival time, planned departure time and how interesting the person is.

    Guests arrive and go first to the bar. From there they mingle by trying to move a square at a time if it will make the average "interestingness" of those surrounding that square more interesting that the average surrounding their current square.

    If the guest cannot move to a square such that the surrounding guests are, on average, more interesting the guest is then he will go back to the bar.

    One last provision...each trip to the bar causes a guest to become one point less interesting but to think he is one point more interesting and each drink also increments the planned departure time by one.

    --

    ~~~~~~~
    "You are not remembered for doing what is expected of you." - Atul Chitnis
    1. Re:Mazes and parties by ChadN · · Score: 5, Funny

      Solving a maze is a good example of recursion.

      So is solving a maze.

      --
      "It's overkill, of course. But you can never have too much overkill." - Anonymous Slashdot Coward
  4. Two points: by devphil · · Score: 3, Interesting


    First:

    The class is generally populated by students from a wide range of backgrounds and interests-liberal arts and science types. While we use C++, the language isn't really the issue.

    You'd better believe it's the issue. Language determines design is a Bell Labs aphorism. Another way of saying the same thing is that the (human) language in which you think and speak determines what you can think and speak about.

    While I happen to be a big fan of C++, I will go on record as saying that it's not a good language to use for beginner programmers. (Neither is Java.) I'd say either Python, or Pascal (you know, that language whose major design goal was to teach introductory programming).

    At least, if you are going to use C++, use a good text like Accelerated C++ by Koenig and Moo. Otherwise you'll spend too much time teaching "how to use C++" and not enough time teaching "how to write a good program."

    Second:

    Rather, the goal is to introduce basic programming ideas like loops, logic, modular programming etc. What are some of your favorite programming assignments that would be appropriate for students at this level?

    My favorite prof in the intro sequence gave us a module that drew playing cards on the screen. (All ASCII-based with ANSI escape sequences for colors, no annoying graphics programming.) We had to write the logic to play Solitaire.

    While there are a lot of problems that CS majors would find cool to solve, those aren't necessarily the same ones that will grab the interest of people "from a wide range of backgrounds," as you say your audience is.

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)
  5. I've always found by Rombuu · · Score: 4, Funny

    ..making students prove NP=P is a good assignment for 1st year students.

    --

    DrLunch.com The site that tells you what's for lunch!
  6. You guys are all nuts!!! by Anonymous Coward · · Score: 5, Interesting
    I taught second quarter C/C++ about five years ago; the students were supposed to have had at least one quarter of C/C++ under their belts. I started off trying to give them an appreciation for the imperfection of computers. For instance, I tried to teach them that if you're dealing with ints, and you add 1 to (2^31 - 1), you don't get 2^31, but rather -2^31. I also tried to teach them that floats become granular at 2^24, i.e. if you add 1 to the float 2^24, you don't get (2^24 + 1), but rather (2^24 + 4). The class revolted, went to the dean [who let most of them transfer to a different section], and I was nearly fired.

    If you're one of the posters on this thread who thinks that a bunch of liberal arts losers are going to program pool table simulations and Mandelbrot sets, then you're living in a fantasy world.

    The following is THE MOST DIFFICULT homework problem they were able to solve: Write a C function that takes an int, and returns one of the strings "st", "nd", "rd", or "th" to describe the ordinality of the associated number [e.g. 1 returns "st", for "1st", 2 returns "nd", for "2nd", 3 returns "rd", for "3rd", 4 returns "th", for "4th", etc.] The trick was that e.g. 11 returns "th", but 21 returns "st". A handful of them were able to get that right.

    The final project was to write a program that would take large files and decompose them into smaller chunks, each small enough to fit onto a 1.44MB floppy. Not a single student in the class came close to finishing the project, and the class included at least three fellows who were already programming for a living.

    1. Re:You guys are all nuts!!! by kraf · · Score: 3, Funny

      And now to Final Jeopardy...
      Write anything !

    2. Re:You guys are all nuts!!! by t · · Score: 3, Interesting
      Disclaimer: I am an Electrical Engineer.

      This is my biggest complaint about Comp Sci degrees. Many of these people are useless programming anything with math. At my old company, I would rather hire a math guy with zippo programming experience because it was easy for those people to pickup programming. Just try and teach a CS guy math! I seriously wish they would start differentiating the degrees, e.g., Comp Sci with specialty in numerics or something.

      That kind of nonsense is why there's 50+ email clients and only a handful of the important things like audio/video compression etc... Things with numbers.

  7. sort by rabiteman · · Score: 3, Interesting

    In high school AP C++ class, when we were learning about sorting my teacher mentioned the different 'standard' sort algorithms, describing how they worked theoretically, and how some were n! and some were n log n, but we never actually compared the output of programs using the different methods. Out of boredom one day I went and made a program that generated a bunch of random arrays of various and then timed how long it took each of six or so algorithms to sort them all. I took the output and graphed it in Excel (being too lazy to make my own graphs ;) and sure enough the better sorts did much better. Coding several different algorithms to perform the exact same task may seem needlessly redundant (because it most certainly is) but it's a great way to get a grasp of loops & recursion &c.

    --
    Oh cruel fate, to be thusly boned! Ask not for whom the bone bones; it bones for thee. -Bender

  8. Ah, 15-127 by nadador · · Score: 4, Insightful

    (Oh, to be a freshman again. To take a "programming" class. To never have heard things like "this implementation is O of log n" or "NP complete" or "software cost estimation" or "preemptive fixed priority scheduling"...)

    The only assignment I remember from my first programming class was one in which we read in stuff from a file into a linked list, printed it forwards and then printed it backwards. The abstraction of the linked list was so cool, and when it actually worked I felt like king of the nerds (little did I know the horrors to come).

    When I was at CMU, there was one intro to programming class, and it was no fun for anyone. Now they've broken it up into people-who-might-take-another-CS-class, and people-who-don't-like-smelling-like-the-cluster, hence a class that is very light on fun and heavy on syntax and object oriented garbage, and one light on programming and heavy on pointy clicky fill in the blanks and make a game happiness.

    stepping onto my soapbox:

    While we're talking about intro classes, I think everyone who is going to take any additional classes in computer science, especially in the systems area, should take their first class in C, and it should be no fun. Every now and then you can toss them something fun, but learning the discipline of malloc/free, strncmp, etc., will serve you so well when you get to do object-y type computer science stuff. Writing good code, in a scientific or engineering sense, is just like learning to use UNIX - if you didn't suffer, you didn't learn. And if you get to new/delete or just new and then forget about it, you never learn the discipline that writing good code demands.

    -- steps off soapbox.

    --

    Outside of a dog, a book is a man's best friend. Inside a dog, its too dark to read.
  9. First year by bertok · · Score: 5, Interesting
    I studied Computer Science at the University of New South Wales. The introductory computer course in first year was "Comp 1A". Instead of C, C++ or Java, we started with a language called Haskell, a pure functional language. Everything has to be an input to a function, or an output - no local variables, no assignment, no loops. The only available form of high level flow control is recursion. After a few weeks, we could write functions to solve simple problems like: Write a function that has an integer input 'n' that returns a square character array representing the image of a square with side-length 'n'. Trivial stuff, even for beginner programmers.

    Sometime in the fourth week, our lecturer announced the eagerly anticipated first Assignment. I couldn't wait, because I expected to ace it, after all, I had years of programming experience, a huge advantage over my peers. Not so: We had to write an Optical Character Recognition (OCR) program. I was stunned. I had never done anything that complex in my life, in any language, and now I was being asked to do it in a functional language! However, many people achieved recognition rates over 80%, and some people rates as high as 98%, even though most students were first-time programmers. It just goes to show what people are capable of when pushed.

    The same lecturer (Andrew Taylor) later came up with a whole series of Evil assignments -- his students tell stories about them to this day. For example, our second assignment in Comp 1A was to write an AI for the card game Hearts. To mark the assignment, he wrote a system that ran submissions in randomly chosen four-player games automatically, and ranked them by total score after some number of games. Half the marks were based on the performance of your AI! He even made the ranking software available beforehand so that students could test their algorithms against each other in mini-tournaments.

  10. Re:The programming assignment I remember by pete-classic · · Score: 3, Insightful

    Most of the suggestions have been too hard and/or in the wrong language. This one is WAY too easy. AND it doesn't teach any 1st semester CS stuff. Well, okay, one loop.

    As for a general response, all the books that I used for CS (C++ 1,2,3 and intro is asm) Had both example projects and "problems" at the end of the chapter. Why don't you open the text you are teaching out of or *gasp* go down the hall to the library and check some books out.

    One I happen to remember is along the lines "Write a program that guesses a number between 1 and 1000 in as few guesses as possible. Detect lying by the player." This is a perfect first semester problem. It forces the use of screen and keyboard I/O, it forces the use of loops. By assignment you can demand that it is broken down into functions. It introduces the idea that you have to detect and deal with bullshit input.

    Finally, to all those to say "make it something fun" or "make it games" GROW UP. Go to a bullshit "tech institute" if you need the professor to spoon-feed you and forcibly retain your interest.

    -Peter

  11. Some good beginner exercises by ttfkam · · Score: 4, Interesting

    Give the model of a deck of cards where the first card is the 2 of spades, the second is the 3 of spades, the thirteenth is the ace of spades, the fourteenth is the two of hearts, etc. In other words, each card in the deck (minus jokers) is assigned a number.

    When given a number from 1 to 52, spit out the name of the card to which it refers. If you want to make it interesting, tell them to solve it twice, using a different method each time. This has two probable solution types: 52 element lookup table or judicious use of the modulus operator. At the end of the assignment, there is usually a small amount of code (easier for beginners to debug -- easier to grade), but gets the gears turning for people not used to thinking in terms of algorithms.

    Keep your eye on those folks who write out a series of 52 if-else-statements or a giant switch statement; they're going to need some tutoring soon.

    ---

    Enter a number as input and spit out that number in hexadecimal and octal.

    ---

    Enter a number under 100 and spit out that number in longhand (36 turns into "thirty six")

    ---

    Read in a variety of data (user's name, age, favorite color, etc.) and spit it back out in a pleasant greeting: "Hello <name>! You are <age> years old and your favorite color is <color>."

    ---

    These aren't horribly difficult -- so you won't drive many people away -- but you still have the opportunity to teach basic I/O, general style, adequate commenting, algorithm efficiency, and (most important) how to approach real-world questions in the step-by-step manner required in programming (multi-threaded/multi-process smart-ass programmers here on /. can shut up now -- this is an introductory class).

    Far too many people who program suffer from lifelong-geek syndrome: knowing how to program for so long that they've forgotten what it was like to learn how to program. As long as you demonstrate sufficient patience, anyone can be taught basic programming skills. I truly believe that most can grok pointers as well assuming they stick with programming long enough and have a good enough teacher.

    Good luck with the class.

    --

    - I don't need to go outside, my CRT tan'll do me just fine.
  12. Honestly, games by KurdtX · · Score: 4, Interesting

    Games are good because not only do they encompass a wide variety of possibilities, but they are acessable to everyone. None of my (non-programmer) friends cared that I could do the tower of Babel in x lines of code, but they liked my simple race car game I wrote in assembly (it was only single player). The coolest was the space invaders we did at the end of my 101 class; the TAs provided a mostly complete graphics library (so we could use images or shapes to make the baddies), and the really bored/advanced students modified the graphics library to change the players ship, weapons, ect. so there was something to challenge everyone.

    --

    Kurdt
    I'm not anti-social. Just pro-technology.
  13. Give them some broken code... by Zocalo · · Score: 4, Interesting
    One of the more useful assignments I had when learning to code (this was machine code, but the principle stands) was to debug someone else's code. All the code had been produced by the lecturer, but using several styles of writing, comments etc. to simulate a basic algorithm that had evolved into something more advanced. The code had numerous errors, some obvious, some subtle, some downright fiendish. The object was to find and fix the bugs and flaws.

    Ideally you want to ease them into this slowly, give away the location of the first bug - bombing if you enter a string where numbers are expected for example, provide test data for the second and so on. Another important thing is to ensure that if the student chooses to re-write an entire function they don't side step another part of the exercise by obliterating another of your carefully crafted flaws.

    The exercise tests the students understanding of the language, ability to prepare realistic test data, and ability to find common bugs like off-by ones, buffer underruns, overflows and so on. It's also pretty good preparation for the "real world" where you will need to read other code, fix other people's errors and improve their code, besides being damned interesting if done right.

    --
    UNIX? They're not even circumcised! Savages!
    1. Re:Give them some broken code... by Slipped_Disk · · Score: 3, Interesting

      Okay, a day late, but this reminded me of an assignment that is too evil NOT to give your students, especially if you want to teach the basics of GOOD algorithms: Propose a problem (any problem, just make sure it is defined well. Mathematical problems or sequences, something with an elegant (or at least short) recursive solution, etc), and have each member of the class go home and write an algorithm to solve the problem. The next day collect the algorithms and hand them out randomly to other students. Have the students code up the algorithm AS GIVEN, making comments on the algorithm and in their code as they feel is appropriate. This was an assignment in my AP CS A class in 1999, and some of the algorithms were interesting (For example, one of them required the implementer to code an "if loop" (in C++)). Grading was based on (a) your algorithm (correct, clear, implementable), (b) how well you implemented the algorithm given to you (did you follow it or did you improvise your own solution?) and (c) the "quality" of your comments (corrections, etc.) on the algorithm you were given. This assignment was definately a good experience for me. Plus it served a good purpose for our teacher (who took the best algorithm writers/correctors) and used them as (essentially) TAs the next year.

      --
      /~mikeg
  14. What I've wanted to try by bluGill · · Score: 5, Interesting

    I've always wanted to teach a class just so I could give this assignement: Write a RPN calculator that does addition and subtraction, no more. A few rules that are different from every other project: other class mates will see your code; redit will be lost for implimenting functionality byond addition and subtraction; the due date is next week, but you get MANY extra points by getting the assignment to me sooner; class dissmissed, get to work.

    Then the next week I would copy everyone's program, and randomly hand it out to other students, with a new assignment: add multiplication and division to this program, and fix any bugs in the code. Time counts again. Note that even though I say is the random, I will in truth pick out who gets what, those who did a good fast job get aweful programs to work with, while those who did a bad job get good ones, and there will be a comment as each studnet picks up his assignment that this is an example to learn from. After they turn in the completed assignment (remember time counts) they will get another assignment, write a short paper to the author of the program you graded on what you found good/bad. (english skills don't count so long as it is understandable, ideas do)

    Finially, everyone see's how their program looked after the second guy got done with it, and the comments. Grades for the second half will take into account how the first half turned out, so someone who got a horrid, non-working assignment and took all week to make some stupid algorithm work will get as much points as someone who was able to get their assignment done in an hour. How long it took the second programer to modify the orginal code is a factor, but minor since bad programs should not take down easy to modify code.

    Just make sure that this is done early in the year, if they are supposed to learn C++ in your class, this won't work, by the time they can do this all their other classes are in crunch time and a good student may notbe able to get this done quickly. I recomend giving this assignment the first day of class, if they can't hack it then, they need more expirence than your class can give.

  15. Re:immediate, fun feedback by bluGill · · Score: 3, Insightful

    then the staff (you) could write a nice gui

    I like this bit of evilness: write your GUI beforehand, and then write a specifican, but make it wrong. Tell the students that the GUI won't be ready for a week, but they will be graded on how they interact with the GUI. Tell the class to write the program and test code to prove the interface works (error checking not required). On the day the assignment is due, collect the their program and the test code, and give them the GUI in library format (previously announced that way of course). Make sure the library doens't impliment the specification, but just tell the students "I will be testing with this GUI, not your test program, since you didn't have time to test with my implimentaiton I'll accept revised versions that work for one week, you will lose points, but not as many as if your program doesn't work. Of course you know that their program will not work with the GUI so they don't lose points, they just sweat a little.

    Evil, but fun to do, and it fits the real world very closely.