COMP 151-251 Spring-Fall 2007

Spring 2007, COMP 151 Object-Oriented Programming [3-0-2:3]
Lecture 2, MWF 15:00-15:50, Rm 2464
Prof. Dekai WU, Rm 3539, 2358-6989,

Lab 2A TA: Zhifeng LAI, Tu 13:00-14:50, Rm 4214,
Lab 2B TA: Jackie LO Chi Kiu, Tu 15:00-16:50, Rm 4214,
Lab 2C TA: Lars SONG Chengqi, Tu 17:00-18:50, Rm 4214,
Support TA: Yihai SHEN,

Fall 2007, COMP 251 Programming Languages [3-0-1:3]

You are welcome to knock on the door of the instructor any time. The TAs' office hours are posted at


Always check for up-to-the-minute announcements.
Lab info is at
Newsgroup is hkust.cs.class.151. Always read before asking/posting/emailing your question.

2007.05.01: Assignment 4 will be due Tue 15 May 2007 at 23:00 via CASS. To finish in time, you must start immediately and aim to finish by 11 May. Remember again, in this class you are learning to engineer a complete software project, and future COMP251 assignments depend on successfully completing A4.

2007.04.18: Midterm grades are released. If you wish to inspect your midterm, please come to Rm 2578 on Mon 24 Apr from 15:00-16:30.

2007.04.13: Two makeup lectures will be held Tue 17 Apr 19:00-21:00 in Rm TBA (following your vote in lecture).

2007.04.12: Assignment 3 will be due Fri 27 Apr 2007 at 23:00 via CASS. Remember again, in this class you are learning to engineer a complete software project, and all future assignments depend on successfully completing A3. To help you check your project's current level of correctness, we're giving you all the Assignment 2 test cases together with the correct outputs. a2_dev_set.tar.gz contains the same test cases we already previously released to assist you while you were still developing A2. a2_test_set.tar.gz contains the new test cases that were used to grade the final A2 versions you submitted.

2007.03.12: Assignment 2 will be due Wed 28 Mar 2007 at 23:00 via CASS. To finish in time, you must start immediately and aim to finish by 21 Mar. Remember again, in this class you are learning to engineer a complete software project, and all future assignments depend on successfully completing A2. Use the newsgroup hkust.cs.class.151 for questions and answers. You are responsible for reading the newsgroup daily.

2007.02.14: Assignment 1 will be due Tues 6 Mar 2007 at 23:00 via CASS. To finish in time, you must start immediately and aim to finish by 1 Mar. Remember, in this class you are learning to engineer a complete software project, and all future assignments depend on successfully completing A1. Use the newsgroup hkust.cs.class.151 for questions and answers.

2007.02.09: Two makeup lectures will be held Mon 12 Feb 19:00-21:00 in Rm 2407 (following your vote in lecture).

2007.01.28: Welcome to COMP151 L2! Labs will begin Tues 6 Feb, in Week 2.


Welcome to this integrated COMP 151-251 yearlong sequence, which takes over where COMP 104 left off. This sequence is designed to give you the solid software engineering experience necessary to build, extend, and maintain a realistically sized non-toy program, using both traditional and up-to-date techniques that you will need on the job. Most students find that C++ and other modern languages offer a huge, confusing variety of different and often-contradictory complexities. In this sequence you will untangle the confusion by gaining an enhanced holistic theoretical perspective, comparing and contrasting the most important paradigms of programming languages.

Understand by doing. The only way to learn languages is through serious practice. The only way to appreciate software engineering is to engineer some serious software. And by far the best way to understand programming languages is to implement one.

So, through a yearlong series of programming assignments, you will use C++ to gradually implement your own complete interpreter for a real programming language that is a small but fully operational version of Scheme (or Lisp).

Beginning in 151, you will learn the most important procedural, static and dynamic object-oriented, and generic programming paradigms of C++ programming, through hands-on practice with building the basic pieces of your Scheme interpreter. Then in 251, you will continue deepening the C++ and Scheme concepts you have learned, and further transition to better understand their functional and generic programming roots and foundations. We will also learn about the syntactic description and analysis of programming languages, and their runtime environments. Toward the end we will extend our learning to logic programming, which is a powerful paradigm that has yet to become widely exploited in typical C++ environments. Throughout the entire series, you will focus on developing adequate software engineering habits, so that you can continue to build, extend, and maintain the code you have built so far.

Academic Calendar Description

151. Object-oriented programming concepts and techniques. Software reuse. Classes, objects, and methods. Abstract data types. Object creation and initialization. Message passing. Class hierarchies and inheritance. Polymorphism. Templates and algorithm abstraction. Prerequisite: COMP 103 or COMP 104

251. Comparative studies of programming languages, programming language concepts and constructs. Non-imperative programming paradigms: object-oriented, functional, logic, concurrent programming. Basic concepts of program translation and interpretation. Storage allocation and run-time organization. Prerequisite: COMP151/151H and COMP171/171H


Reference Books


To receive a passing grade, you are required to sign an honor statement acknowledging that you understand and will uphold all policies on plagiarism and collaboration.


All materials submitted for grading must be your own work. You are advised against being involved in any form of copying (either copying other people's work or allowing others to copy yours). If you are found to be involved in an incident of plagiarism, you will receive a failing grade for the course and the incident will be reported for appropriate disciplinary actions.

University policy requires that students who cheat more than once be expelled. Please review the cheating topic from your UST Student Orientation.

Warning: sophisticated plagiarism detection systems are in operation!


You are encouraged to collaborate in study groups. However, you must write up solutions on your own. You must also acknowledge your collaborators in the write-up for each problem, whether or not they are classmates. Other cases will be dealt with as plagiarism.


The course will be graded on a curve, but no matter what the curve is, I guarantee you the following.

If you achieve 85% you will receive at least a A grade.
75% B
65% C
55% D

Your grade will be determined by a combination of factors:

Midterm exam ~20%
Final exam ~25%
Participation ~5%
Homework ~40%
Labs ~10%


No reading material is allowed during the examinations. No make-ups will be given unless prior approval is granted by the instructor, or you are in unfavorable medical condition with physician's documentation on the day of the examination. In addition, being absent at the final examination results in automatic failure of the course according to university regulations, unless prior approval is obtained from the department head.

There will be one midterm worth approximately 20%, and one final exam worth approximately 25%.


Software engineering is about communication between people. Good participation in class and/or the online forum will count for approximately 5%.


All programming assignments must be submitted by 23:00 on the due date. C++ programming assignments must be compiled using g++ on Unix and will be collected electronically using the automated CASS assignment collection system. Late assignments cannot be accepted. Sorry, in the interest of fairness, exceptions cannot be made.

Programming assignments will account for a total of approximately 40%.


All information for laboratory assignments is at

Laboratory assignments will be announced at the end of each week, and will be due on the following Friday at 23:00. Laboratory assignments must be in C++ on Unix and will be collected electronically using the automated CASS assignment collection system. Late assignments cannot be accepted. Sorry, in the interest of fairness, exceptions cannot be made.

You will also have the option to turn in your laboratory assignments in lab by demonstrating to the TA. This will also give you an opportunity to get an early indication of whether your assignment is correct. If not, you may still decide to fix it, and then wait until the Friday 23:00 CASS collection to turn in your assignment.

There will be up to 10 laboratory assignments, which in total will count for approximately 10%.


Date Wk Event Paradigm Topic Notes Reading Assignments
2007.01.29 1 Lecture Administrivia (honor statement, HKUST classroom conduct) Business Week, The Perils of JavaSchools
2007.01.31 1 Lecture SwEngr Introduction: C++ and software engineering (doxygen notes: Marine's, Adam's) V1.Ch1
2007.02.05 2 Lecture Procedural Introduction (cont) (self-review: References, Const) V1.Ch3,
2007.02.07 2 Lecture SwEngr Introduction: Data abstraction V1.Ch2
2007.02.09 2 Lecture SwEngr Introduction: Data abstraction (cont) (YourPets2a.cpp, YourPets2b.cpp) V1.Ch4
2007.02.12 3 Lecture Procedural Declaration and definition (reverse_print.cpp, use_reverse_print.cpp, reverse_print.hpp) V1.Ch5
2007.02.12 3 Lecture StaticOO Overloading and constructors (Makeup lecture Rm 2407 19:00-20:00) V1.Ch6
2007.02.12 3 Lecture StaticOO Destructors (Makeup lecture Rm 2407 20:00-21:00) V1.Ch6
2007.02.14 3 Lecture StaticOO Order of construction/destruction, Post Office example, argc & argv V1.Ch6
2007.02.16 3 Holiday Lunar New Year
2007.02.19 3 Holiday Lunar New Year
2007.02.21 3 Holiday Lunar New Year
2007.02.23 3 Lecture StaticOO Inheritance: Introduction V1.Ch14
2007.02.26 4 Lecture StaticOO Inheritance: Substitution principle V1.Ch14
2007.02.28 4 Lecture Functional Project (Assignment 1): Encapsulation, s-expressions, cons lists, tagged unions, eval
2007.03.02 4 Lecture StaticOO Inheritance: Access control: public, protected, private V1.Ch14
2007.03.05 5 Lecture DynamicOO Inheritance: Virtual functions V1.Ch15
2007.03.06 5 A1 due
2007.03.07 5 Lecture DynamicOO Inheritance: Overriding vs overloading V1.Ch15
2007.03.09 5 Lecture DynamicOO Inheritance: Abstract base classes, ex1, ex2, ex3, ex4 V1.Ch15
2007.03.12 6 Lecture Functional Project (Assignment 2): Polymorphic reimplementation, exposing car/cdr/cons/nullp
2007.03.14 6 Lecture StaticOO The "this" pointer V1.Ch4
2007.03.16 6 Lecture StaticOO Inheritance: Public, private, protected inheritance V1.Ch14
2007.03.19 7 Lecture SwEngr Exceptions V2.Ch1
2007.03.21 7 No lecture
2007.03.23 7 No lecture
2007.03.26 8 No lecture
2007.03.28 8 A2 due
2007.03.30 8 Exam Midterm (LTA 19:00-21:00; sample exam for your practice)
2007.04.02 9 No lecture due to Midterm
2007.04.04 9 Holiday Mid-Semester Break
2007.04.06 9 Holiday Mid-Semester Break
2007.04.09 9 Holiday Mid-Semester Break
2007.04.11 9 Lecture Generic Introduction to generic programming V1.Ch16
2007.04.13 9 Lecture Generic Function and class templates V1.Ch16
2007.04.16 10 Lecture Generic Overloading operators V1.Ch12
2007.04.17 10 Lecture Functional Project (Assignment 3): Exceptions, boolean operators, exposing eval & print (Makeup lecture Rm 4619 19:00-22:00)
2007.04.17 10 Lecture Functional Project (Assignment 3): Symbol tables, the define operator, STL map (Makeup lecture Rm 4619 20:00-21:00)
2007.04.18 10 Lecture Generic Container classes V2.Ch7
2007.04.20 10 Lecture Generic STL: Sequences & Iterators V2.Ch6
2007.04.23 11 No lecture
2007.04.25 11 No lecture
2007.04.27 11 No lecture A3 due
2007.04.30 12 Lecture Generic STL: Introduction to algorithms V2.Ch6
2007.05.02 12 Lecture Generic STL: Function pointers V2.Ch6, ref V1.Ch3
2007.05.04 12 Lecture Generic STL: Function objects or functors V2.Ch6
2007.05.07 13 Lecture Generic STL: More algorithms V2.Ch6
2007.05.09 13 Lecture Functional Scope and Parameter Passing
2007.05.11 13 Lecture Functional Activation Records
2007.05.14 14 Lecture SwEngr Namespaces V1.Ch10
2007.05.15 14 A4 due
2007.05.16 14 Lecture SwEngr Static V1.Ch2
2007.05.21 15 Exam Final (S H Ho Sports Hall 16:30-19:30; sample final exam plus a sample midterm and another sample midterm for your practice)
COMP251 (tentative)
2 Lecture Introduction, Administrivia (honor statement, HKUST classroom conduct) Ch1
2 Lecture Syntax Language Description Ch2.1 - Ch2.3
3 Lecture Syntax Grammar Ch2.4 - Ch2.5
3 Lecture Syntax Grammar, cont'd  
4 Lecture Syntax Regular Grammars  
4 Lecture Syntax Lex (GNU Flex) Flex user manual
5 Lecture Syntax Yacc (GNU Bison) Bison user manual, FLEX and BISON on WIN32 platform
5 Lecture Syntax Yacc (GNU Bison), cont'd
6 A5 due
7 Exam Midterm (Room TBA 18:00-21:00 )
7 Lecture Functional Scheme/Lisp, Function Values, Lambda Ch10.1 - Ch10.3, Scheme R5RS
8 Lecture Functional Functions and Lambda Ch10.1, Ch8.3-Ch8.4, Ch9.2 - Ch9.4
8 Lecture Functional Lambda Calculus Ch14.1
9 Lecture Functional Scope and Let Statement Ch10.1, Ch8.5
9 Lecture Generic/Functional Introduction to SML, Types Ch8, Ch8.6, Ch9.1
9 A6 due
10 Lecture Generic/Functional Datatypes, Miscellaneous and Summary Ch9.5, Ch9.6
10 Lecture Logic Introduction to Prolog Ch11.1
11 Lecture Logic Fact, Rule, and Program Ch11.2
11 Lecture Logic List Ch11.3
12 Lecture Logic Unification and Substitutions Ch11.5
14 A7 due
12 Lecture Logic Unification and Substitutions, cont'd  
13 Lecture Logic Cuts Ch11.6
13 Lecture Logic Programming Techniques Ch11.4
14 Lecture Review    
14 A8 due
14 Lecture Review
15 Exam Final (16:30-19:30, LG4204)
Last updated: 2007.05.09