CS1101C Lab Tips

  1. Practice as many tutorial questions as you can before coming for the lab. The lab is not a practice session; it is an assessment session to assess how well you know the lab topics and how much prior practice you have done beforehand.

  2. Do not let anyone see your code. Do not send anyone your code. It is your responsibility to protect your own code from other students’ eyes. If someone sees your code and copies sections from it and is caught by the plagiarism checker, both the copier (your friend) and the provider (you) get zero marks for the lab, as well as the opportunity to see the higher authorities for possible disciplinary action.

  3. Do not discuss detailed algorithms with your friends. That translates into groupwork which is not allowed and will be deemed as copying. This is an individual lab assignment. Same consequences as Point 2 above.

  4. Find other ways of helping your friends if they need help. Do not spoonfeed them with C code. Help them to come up with the solution on their own.

  5. Follow the five step problem solving methodology taught in the lectures.

  6. Break down a large problem into many smaller manageable parts. Test each small part individually with hand examples and write small chunks of code (usually just a few lines!) that compiles and runs for each small part. The smaller each part is, the easier it is to test. This makes it much easier to detect and fix all kinds of errors.

  7. Write separate functions for each of the modules. This makes it easier to test your program.

  8. Test your program with small amounts of iterations first. E.g. do not test your program with 1,000,000 simulations, but with 5 simulations or so (less if your program is buggy). If there are logical errors or strange runtime errors like "Segmentation Fault", "Bus Error", or "Arithmetic Exception", print out the values of all your variables to see where the error lies.

    Sementation Fault and Bus Error usually means you tried to access some memory that does not belong to you. Arithmetic Exception usually means a divide-by-zero error occurred.

  9. To find out exactly which line causes runtime errors like "Segmentation Fault", "Bus Error", or "Arithmetic Exception", insert printf statements into your code, similar to this:

    /* Code segment A. */
    printf("1. (What is happening?)\n"); /* The \n is important! */
    /* Code segment B. */
    printf("2. (I am seeing stars.)\n");
    /* Code segment C. */
    printf("3. (I want to sleep!)\n");
    /* Code segment D. */
    

    If you run your program and see:

    1. (What is happening?)
    Segmentation Fault
    

    you know that the error lies in Code Segment B. If you run your program and see:

    1. (What is happening?)
    2. (I am seeing stars.)
    Segmentation Fault
    

    you know that the error lies in Code Segment C. And so on.

  10. As far as you can, work towards finishing the lab within 2 hours, preferably less. In the practical exam, you will be given exactly 1 hour and 45 minutes.

  11. Submit your work each time you get a compilable program, even though your program is incomplete. This builds up good habits in preparation for the practical exam. The worst thing to do is to miss the submission deadline by one second without submitting anything; this results in zero marks, no exceptions (to be fair to everyone).

Last updated: Monday 08 August 2005, 14:32:31 hours.


This document, labtips.html, has been accessed 27 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 20 different hosts have accessed this document in the last 444 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 5 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.