Week 01 (Monday)


COMP1921 16s2 Computing 1B1/42

( Introduction to (C) Programming (continued) )

[Diagram:Pic/cselogo-small.png]

Ashesh Mahidadia


Web Site:   http://www.cse.unsw.edu.au/~cs1921/16s2/


COMP1921 16s2 Course Convenor2/42

Name:Ashesh Mahidadia
Email:ashesh@cse.unsw.edu.au
Research:Artificial Intelligence, Machine Learning, Knowledge based Systems


COMP1921 16s2 Tutorials and Labs3/42

Name:Mei Cheng Whale
Phone:9385 5683
Email:meicheng@cse.unsw.edu.au


Course Aims4/42

This course aims to extend your programming knowledge

Ultimately, to get you to the point where


Access to Course Material5/42

All course information is placed on the course website:

Slides/Tutorials/Labs are publically readable.

If you need to post/submit/etc, you need to login.


Inputs6/42

At the start of this course you should be able to:


Exercise: C revision7/42

On a piece of paper, write a C program that:

Program must be complete, including Five minute time-limit.


Outputs8/42

At the end of this course you should be able to:


Schedule9/42

WeekLecturesChNotes
02Intro, C revision, C execution model 1-6 First tute/lab
03Single-, multi-dimensional arrays & pointers 7 -
04Testing, debugging, performance - -
05Structured data types 8 Quiz 1
06Dynamic memory allocation 10 -
07Linked lists 10 Assignment released
08Stacks and queues10 -
09Abstract data types 10 Quiz 2
10Binary trees 10 -
11Random numbers, File operations 11 -
12Sorting algorithms 12 -
13Problem solving strategies 9 Final tute/lab, Assignment due


Credits for Material10/42

Always give credit when you use someone else's work.

Ideas for the COMP1921 material are drawn from


Resources11/42

Textbook:

Additional reference material: Also, numerous online C resources are available.


Lectures12/42

Lectures will:

Lectures provide an alternative view to textbook.

Lecture slides will be made available before lecture.

Feel free to ask questions, but No Idle Chatting.


Tutorials13/42

Tutorials aim to:

Tutorials start this week (Week 2)

Tutorial and lab exercises available on web Thursday the week before


... Tutorials14/42

To get the best out of tutorials

Ask your tutor if ...

To get the most from tutorials ... participate


Lab Classes15/42

Each tutorial is followed by a two-hour lab class.

Lab exercises aim to build skills that will help you to

Lab classes give you experience applying tools/techniques.

Each lab exercise is a small implementation/analysis task.

Do them yourself!   and   Don't fall behind!


... Lab Classes16/42

Lab exercises contribute 10% to overall mark.

In order to get a mark, lab exercise for Week X must be

There will be no appeal to lab marks awarded
(because individual exercises are worth only a small fraction of your final mark)

You can work in teams of two for the lab exercises


Quizzes17/42

There are 2 'mid-session' quizzes: one each in weeks 5 and 9.

The quizzes contribute 5% (week 5) + 15% (week 9) = 20% to overall mark.


Assignment18/42

The assignment gives you experience applying tools/techniques
(but to a larger programming problem than the lab exercises)

The assignment will be carried out individually.

The assignment is due at 11:59pm, Friday, Week 13.

15% penalty will be applied to the maximum mark for every 24 hours late after the deadline.

No submissions will be accepted after Wednesday of Week-14.

The assignment contributes 15% to overall mark.


... Assignment19/42

Advice on doing the assignments:

They always take longer than you expect.

Don't leave them to the last minute.

Organising your time no late penalty.

If you do leave them to the last minute:


Plagiarism20/42

You attempt Labs and Assignments unsupervised ...

Plagiarism = submitting someone else's work as your own.

We get very annoyed by people who plagiarise.

Plagiarism will be checked for and punished.

You must be able to demonstrate and explain programs to your tutor.

It's not clever to try to get through this course by copying.

Most of you will be doing more computing in your own schools.


... Plagiarism21/42

We frown on plagiarism BUT ...

Normally, you are not allowed to re-use others' code in this course.

In some places, we will allow it


Final Exam22/42

3-hour on-line exam during the exam period.

Held in CSE labs   (must know lab environment)

Some on-line documentation will be available.

Format:

Questions will be similar in style to tutorial and lab questions.


... Final Exam23/42

How to pass the Exam:


Supplementary Exams24/42

You can apply formally for special consideration

If you attend an exam


Assessment Summary25/42

labs   = mark for labs        (out of 10)
quiz1  = mark for quiz 1      (out of 5)
quiz2  = mark for quiz 2      (out of 15)
ass    = mark for assignment  (out of 15)
exam_w = mark for written part of final exam (out of 20)
exam_c = mark for coding part of final exam  (out of 35)

mark   = labs + quiz1 + quiz2 + ass + exam_w + exam_c

To pass the course, you must achieve:


How to Pass this Course26/42

Programming is a skill that improves with practice.

The more you practise, the easier will be labs/quizzes/assignment/exam.

Don't restrict practice to lab times and two days before assignment due.

It also helps to pay attention in lectures and tutorials.


Summary27/42

The goal is for you to become a better programmer


Exercise: Integers between N and M28/42

Consider the program to print the first 10 integers.

Modify it so that can ...

Use sscanf() to create an integer from a string. Example:

int n;
sscanf(argv[1], "%d", &n);


C Language/Style


COMP1921 Style30/42

Extends the range of allowed constructs:


... COMP1921 Style31/42

Good: gives you more freedom and power

Bad: gives you more freedom and power

So, you must still use some discipline.


Sidetrack: Obfuscated Code32/42

C has a reputation for allowing obscure code, leading to ...

The International Obfuscated C Code Contest


... Sidetrack: Obfuscated Code33/42

Most artistic code (Eric Marshall, 1986)


                                                   extern int
                                                       errno
                                                         ;char
                                                            grrr
                             ;main(                           r,
  argv, argc )            int    argc                           ,
   r        ;           char *argv[];{int                     P( );
#define x  int i,       j,cc[4];printf("      choo choo\n"     ) ;
x  ;if    (P(  !        i              )        |  cc[  !      j ]
&  P(j    )>2  ?        j              :        i  ){*  argv[i++ +!-i]
;              for    (i=              0;;    i++                   );
_exit(argv[argc- 2    / cc[1*argc]|-1<4 ]    ) ;printf("%d",P(""));}}
  P  (    a  )   char a   ;  {    a  ;   while(    a  >      "  B   "
  /* -    by E            ricM    arsh             all-      */);    }


... Sidetrack: Obfuscated Code34/42

Just plain obscure (Ed Lycklama, 1985)


#define o define
#o ___o write
#o ooo (unsigned)
#o o_o_ 1
#o _o_ char
#o _oo goto
#o _oo_ read
#o o_o for
#o o_ main
#o o__ if
#o oo_ 0
#o _o(_,__,___)(void)___o(_,__,ooo(___))
#o __o (o_o_<<((o_o_<<(o_o_<<o_o_))+(o_o_<<o_o_)))+(o_o_<<(o_o_<<(o_o_<<o_o_)))
o_(){_o_ _=oo_,__,___,____[__o];_oo ______;_____:___=__o-o_o_; _______:
_o(o_o_,____,__=(_-o_o_<___?_-o_o_:___));o_o(;__;_o(o_o_,"\b",o_o_),__--);
_o(o_o_," ",o_o_);o__(--___)_oo _______;_o(o_o_,"\n",o_o_);______:o__(_=_oo_(
oo_,____,__o))_oo _____;}


Switch-statements35/42

switch encapsulates a common type of selection:

if (var == Constant1) {
   some statements1;
} else if (var == Constant2) {
   some statements2;
}
...
else if (var == Constantn) {
   some statementsn;
}
else {
   some statementsn+1;
}


... Switch-statements36/42

Multi-way if becomes:

switch (var) {
case Constant1:
   some statements1;
   break;
case Constant2:
   some statements2;
   break;
...
case Constantn:
   some statementsn;
   break;
default:
   some statementsn+1;
}

Note break is critical; if not present, falls through to next case.


Exercise: If / Switch37/42

Convert the following if to a switch:

if (n == 1) {
	printf("One\n");
} else if (n == 2) {
	printf("Two\n");
} else if (n == 3) {
	printf("Three\n");
} else if (n >= 4 && n <= 9) {
	printf("Real Big\n");
} else {
	printf("Huh?\n");
}


Exercise: Count lines in stdin38/42

Write a program that


Programming Tools


Programming Tools40/42

Documentation   (man, info)

Text editors   (vim, emacs, kate, ...) Compilers   (gcc, javac, g++)


... Programming Tools41/42

Version control   (cvs, svn, ...)

Compilation management   (make, ant) IDEs   (eclipse)


... Programming Tools42/42

Debuggers   (gdb, ddd, lldb,...)

Profiler   (gprof)


Produced: 11 Aug 2016