CS201J: Engineering Software, Fall 2003
|
Notes: Thursday 20 November 2003
Schedule
- Monday, 24 November: Review Questions (email to me by 5pm)
- Tuesday, 25 November: PS6 Due
- Tuesday, 2 December: Exam 2 Out
- Friday, 5 December: Exam 2
Exam 2
Exam 2 will be handed out on Tuesday, 2 December and due on Friday, 5 December. The exam will be take home, open book and notes, and similar in format to Exam 1.Exam 2 will cover all material in the class up to and including today's lecture and problem sets 1-6. It will emphasize material covered since Exam 1, but may include questions on any course material. You should not be surprised if it has questions about subtyping, concurrency, design, type safety, Java byte codes and garbage collection. You should also not be surprised to find questions that cover material from the first half of the class also: writing good specifications, reasoning about data abstractions and design.
Tuesday's class will be a review session if and only if enough students send in good questions by Monday.
Pointers in C Why is it useful to be able to manipulate memory addresses directly?
Why is it dangerous to be able to manipulate memory addresses directly?
- &expr — Evaluates to the address of the location expr evaluates to
- *expr — Evaluates to the value stored in the address expr evaluates to
- expr1[expr2] — Syntactic sugar for *(expr1 + expr2)
int match (char *s, char *t) { char *os = s; while (*s++ == *t++); return s; }Clue
Friday's section will review subtyping and concurrency. One problem for tomorrow's section is below. Please look it over before section.In this game of 4 players, the participant who collects 5 clues wins and ends the game. Look at the following code and:
- Describe where the race condition is.
- Explain how to avoid this race condition.
class ParticipantThread implements Runnable { private Participant participant; public ParticipantThread(Participant p) { participant = p; } public void run() { participant.getClue(); } } class Clues { private int numclues; public Clues (int p_numclues) { numclues = p_numclues; } public void removeClue () { numclues--; } public boolesn hasCluesLeft () { return numclues > 0; } } public class Participant { private int num_clues; // number of clues this participant has collected static private Clues clues; public Participant () { num_clues = 0; } public void getClue() { if (clues.hasCluesLeft()) { num_clues++; clues.removeClue(); // decreases the total number of clues in the game } } public static void main(String[] args) { // the four players Participant p1; Participant p2; Participant p3; Participant p4; clues = new Clues (16); // Start with 16 clues Thread p1thread = new Thread(new ParticipantThread(p1)); Thread p2thread = new Thread(new ParticipantThread(p2)); Thread p3thread = new Thread(new ParticipantThread(p3)); Thread p4thread = new Thread(new ParticipantThread(p4)); p1thread.start(); p2thread.start(); p3thread.start(); p4thread.start(); } }The International Obfuscated C Code Contest is a contest to write an incomprehensible C program. Why is there no International Obfuscated Java Contest?
#includeRaymond Cheong's short program from IOCCC 2002 for calculating square rootsint l;int main(int o,char **O, int I){char c,*D=O[1];if(o>0){ for(l=0;D[l ];D[l ++]-=10){D [l++]-=120;D[l]-= 110;while (!main(0,O,l))D[l] += 20; putchar((D[l]+1032) /20 ) ;}putchar(10);}else{ c=o+ (D[I]+82)%10-(I>l/2)* (D[I-l+I]+72)/10-9;D[I]+=I<0?0 :!(o=main(c/10,O,I-1))*((c+999 )%10-(D[I]+92)%10);}return o;}
University of Virginia Department of Computer Science CS 201J: Engineering Software |
Sponsored by the National Science Foundation |
cs201j-staff@cs.virginia.edu |