Bonus questions, templates, example solutions
This page provides some stuff about programming in Python and C for the
COMP5212 course.
You may view your marks here (updated 30 May 2009).
In week 13 lab (4 June), I will give some bonus questions in lab, for people
who are interested to get some bonus marks. If you're interested in attempting those questions, I strongly
recommend you to (nearly) complete your lab work from home. You may want to learn about bitwise operators
to have a better chance solving some of the questions; here is a
tutorial by Dave Marshall.
Example code for labs and homework
FAQ
Q: What are the recommended gcc flags to compile my C program?
A: gcc -Wall -W -ansi -pedantic -g myProgram.c -o myProgram
Q: What does week 7 homework really want us to do?
A: In short, it wants a program that prints every other line of the input until
a line starting with 'Q'. It is probably easier to illustrate this by sample input/output:
1
1
a
123ab
123ab
abcd
Q456
Lines 2 and 5 are output. The last line starts with 'Q', so the rest of it was not read in.
Q: How do I develop C programs under Windows?
A: There are a number of C
compilers you can obtain free of charge. If
you would like to use GCC (and I do recommend this compiler), you will need either MinGW
or Cygwin (refer to GCC's download page).
Q: What is sample input/output for Week 8 homework?
A:
~$ ./homework8
1 2 3 4
a b c
<EOF>
Number of spaces: 5
Where an EOF character is Ctrl-D (on *nix systems) or Ctrl-Z (on Windows).
You might need to hit Enter after Ctrl-Z on Windows.
Q: Can I connect to SIT's machines?
A: You may use an ssh client, such as putty,
to connect to a number of SIT's machines, including congo[1-4].ug,
userf[1-5].ug, ufiler[0-4].ug. So, for example, congo1.ug.it.usyd.edu.au
is a machine you can access, and ufiler2.ug.it.usyd.edu.au is another one.
The login is the same as the one you use in the regular lab.
Q: My C program compiles in [blah] (substitute this with any C compiler
other than GCC, such as Visual C++), but not GCC!
A: Each compiler differs slightly and may provide some non-standard
libraries and/or functions. So, the best thing is to compile your
C programs with GCC (refer to an FAQ about installing GCC on Windows).
Alternatively, you could remotely access an SIT's machine (again, refer
to an FAQ above) and write your C programs with a command-line editor,
such as nano, emacs or vim.
Q: Can I have text highlighting in nano?
A: Yes, by the use of a configuration file. Here is an example of the file:
dot_nanorc. Copy that file and save it under
your home directory (i.e. "~/") as ".nanorc".
Other lab-related sources
- Australian postcode database:
Auspost postcode
Here is a hack to convert the file into the desirable format for week 5 and 6 lab/homework:
postcode_hack.py. Just run the file with the
unzipped postcode database (i.e. pc-full_200900331.csv) in the same directory.
The file "postcodes" would be generated.
Python and C documentations and references:
Programming and debugging tips
- Comment your code consistently and succinctly.
This also helps youself understand what you try to do.
- Pseudo-code before actually coding. This helps make sure the logic is correct.
- Insert some sort of debug prints regularly. It helps debug.
- Paper debug: step through your program with a pen and paper.
Practice programming questions
Here are some sites that contains some programming questions to practice.
- A few questions from Westminister School of IT website:
here
- Some questions of simple computer AI, although many of them
do not have sample input/output, which makes them confusing.
problems
- UVa Online Judge: lots of questions, ranging from
challenging to very challenging! You could also submit your
answers to the automatic judging system, with a free login.
Email me for questions and comments. My IT email is niu@it.usyd...
This page was last modified: 04 June 2009 20:13:27 EST (Sydney time).