tags:

views:

84

answers:

3

I'm giving a small PHP course over the next weekend and i would like to present a few questions and exercises for my students, so they can practice with an objective, a fun one. I already presented the basics for them, now it's time for some action. Any ideas, guys?

+1  A: 

For example u can give them a simple for loop statement and ask them to implement it with while statement or vise versa. and do this for other statements like switch case and if.

rahim asgari
+2  A: 

Finding ways to implement simple algorithms always provides great practice. If you think they're ready for higher level data structures (linked lists, graphs, etc.) then you could give them a Depth-First Search problem. If they're not at that level yet, try working with arrays and for/while loops. You can iterate lots of functions over entire arrays very easily. For example, average the values of an array, sum the values, or create a new array of N-1 elements (where the first array had N elements), each of which is the difference of element N and element N+1 in the original array.

If you want to try any of the examples into the real world, try grade calculation algorithms (given a list of grades, find the GPA) or shopping carts (you bought 1 of item X, 3 of item Y, 2 of item Z... total price?)

You can also make it a bit for complicated by having weighted grades (a B in a 3 hours class and an A in a 1 hour class = a GPA of 3.25)

I would also recommend doing a little bit of work with either databases or files input/output. The ability to save the results of your work and recall them later will GREATLY extend their understanding of complex larger systems like websites.

If you think it's not too complicated (I don't know the level of the students), one assignment I had in a class a couple of years ago (which we did in PERL) could be modified. It involved the following text document:

1           | Billy | Bob   | Kentucky   | Yale
     2 | Sally |     Sue|    Virginia  | Harvard
...

We were told to assume the pattern id | first_name | last_name | state | university, however there could be a variable amount of white-space. There were also some malformated entries, such as:

...
    7  | Joe |  3   |         Ohio  |   MIT
...

Clearly 3 isn't a last name. We were told to use regular expressions to verify that the ID was an integer less than 10000, the first and last names consisted only of letters, the state had to start with a capital letter and be followed by some number of lower-case letters, and the university had to consist only of letters. If there were any errors we had to say what the error was and what line of the file it was on. (For example: "Error on line 7: 3 is an invalid last name. Should be only letters")

After this we entered a loop (our program was interactive and ran from shell) where they could enter 1 for id, 2 for first name, 3 for last name, etc. They entered 0 to quit. Whatever they put in, they could then type a string to search for and it would find a student who matched that criteria and display their information. Instead of an interactive loop, if you're teaching PHP for use on a web server, maybe allow them to submit a form and check the $_POST information.

steven_desu
Thank you very much, Steven. You gave me an idea of having them store form data into a text file and creating a CRUD for that data later on. That will give a very big understanding of strings, as well file operations.
Michael Biel
I really dislike the idea of teaching "generic" programming stuff like "(linked lists, graphs, etc.)". If I'm going to teach php stuff I would go with a more real life example like. Examples are news scripts with a mysql database. Or something like "pizza ordering service" with html forms and such. No need to torture your people with assignments like "how to solve the shortest path problem of a weighed cycle free directed graph...". I'm not using PHP to solve graph problems.
Progman
Generic programming stuff is the core of algorithm and complexity analysis. Not to mention it's the core of most programmatic solutions to our computing world. For instance: let's say you wanted to create a tag system for books. You could give one book the tags "teen", "vampire", "romance" (know what book I'm talking about?). You probably say "oh- just use a many to many relationship". Well that relationship is now well-documented on Google, but it was once an algorithmic problem solved via graph analysis.
steven_desu
On top of which, giving someone an assignment that involves linked lists does not by ANY means that you have to give them a meaningless assignment like "make and sort a linked list of random integers". You could instead tell them to create a list of chores that need to be done, however some chores need to be done before others (you must shower before you get dressed). They need to create "some structure" in code to exemplify this, then find an order in which to perform the chores which will ensure all prerequisites are met.
steven_desu
A good programmer MUST learn the generic and boring solutions, because these can be applied in infinite places. The people who go to "tool school" learn how to solve a single problem and then can't extend that knowledge when a new problem arises. It's the job of a good professor to teach these generic solutions in unique and interesting ways.
steven_desu
A: 

Arrays are a stumbling point for most beginners I know. I'd personally run them through single-and multi-dimensional array looping and stepping. With MVC frameworks becoming so prevalent, the foreach loop and array functions become vital to programming success.

bpeterson76