CMT2050
Object Oriented Programming and Design
Module Handbook
Semester 2
2001/2002
Lecturer: Dr. Xiaohong Gao
School of Computing Science
Contents
Contents 2
1. An Overview 6
1.1 Preface 6
1.2 The module teaching team 6
1.3 About this Handbook 6
2Learning Unit Narrative (LUN) ---- Official Module Information 8
Coursework 10
The Logbook 10
Web Pages 10
The short programming tasks 12
The Individual Project 12
The Group Project 12
course work 1 ---- Short Program Task 1 13
course work 2 ---- Short Program Task 2 15
course work 3 ---- Short Program Task 3 17
course work 4 ---- Individual Program Project 19
course work 5 ---- Group Project 21
Lecture Plan 24
3. Lectures 25
Lecture 1 Object-Oriented Programming (OOP) 25
1.1 Procedural Programming 25
1.2 Object-Oriented Programming 25
Lecture 2 Classes and Data Encapsulation 27
2.1 Introduction 27
An example of class: 27
2.2 Classes 28
2.3 Example Program Using Classes 29
Example Class Definition 29
Example Class Implementation 30
2.4 Data Encapsulation 31
Diagram of Data Encapsulation 31
Lecture 3 Abstraction and Constructors 32
3.1 Abstraction 32
An Interface and Implementation of a Cassette Player. 32
3.2 An Introduction to Constructors 32
3.3 Copy Constructor 34
Lecture 4 Pointer (*) and Destructor (~) 35
4.1 Memory and the whole machine 35
Operating System Core (Kernel) 35
Processes 35
Disk Cache 35
4.2 Memory and the process 36
Executable Machine Code 36
Static Memory 36
Stack Memory 36
Dynamic Memory 36
4.3 Pointers 37
KEY FACTS 37
4.3.1 An Example of Accessing an Array using Pointers 39
4.4 Principles of dynamic memory 40
4.4.1 Objects on the heap 41
KEY FACTS 41
4.4.2 Arrays on the heap 41
KEY FACTS 41
4.5 The Destructor 42
Lecture 5 Polymorphism 43
5.1 Some Definitions 43
Overloading The use of the same (function) name for similar facilities. 43
5.2 Overloading Ordinary Functions 43
5.3 Defaulting Function Arguments 43
An Example of Defaulting Function Arguments 44
5.4 Overloading Constructors 45
4.6 An Example of Overloading Constructors 45
Lecture 6 Composition and Inheritance 46
6.1 Relationships "HAS-A" versus "IS-A" 46
6.2 Composition in Practice 46
6.3 Inheritance 47
What is inheritance ? 47
Example: 47
6.4 Public, Private and Protected members 48
6.5 Public, Private and Protected Derivations 49
Derived Class Access 49
Lecture 7 Object-oriented design using uml 51
7.1 design 51
7.2 UML 51
7.3 use case diagram 52
7.4 use care diagram examples 52
Lecture 8 Static Data Members and Methods, 54
Static Binding and Dynamic Binding 55
8.1 Static Member Variables 55
8.2 Static Member Functions 55
8.3 Static binding 56
8.4 Dynamic binding 56
8.5 An example of Dynamic Binding 57
Step 1 58
Step 2 59
Step 3 59
Lecture 9 Advanced Techniques (1) 61
9.1 Inline Function 61
9.2 Inline Member Functions 62
9.3 Implicit Inlining 63
9.4 Friendship in Principle 64
What ? 64
Why ? 64
How ? 64
9.5 Granting Friendship to an Ordinary Function 65
HINTS 65
9.6 Granting Friendship to a Method of Another Class 66
9.7 Granting Friendship to Another Class 67
Lecture 10 Advanced Techniques (2) 68
10.1 Operator Overloading - in principle 68
10.2 Operator Overloading - the equality test 69
10.3 Operator Overloading - assignment 70
Lecture 11 Templates (extra reading) 71
11.1 Function Templates 71
What are function templates ? 71
Why use function templates? 71
11.2 Example code without function templates 71
11.3 Creating a function template. 72
11.4 Using function templates. 72
11.5 Function templates with multiple data types 73
11.6 Class Templates 74
Example program using the class template 76
11.7 Container Classes and the S.T.L. 77
4 Materials for Lectures 78
5. Materials for Seminars 79
Seminar 1. Pre-Processors 79
1.2 The phases of compilation 80
1.3 The Role of the Preprocessor 83
Seminar 2. Exerices 85
Seminar 3 Exercises 88
Seminar 4 Exercises 89
Seminar 5 Exercises 90
Seminar 6 Exercises 91
Seminar 7-10 Group Project Meeting 91
Seminar 11 Group Project Presentation 91
Materials for Labs 92
Lab 1. Using C++ Builder to create projects 92
Lab 2 Exercises 93
Lab 3 Exercises 93
Lab 4 Exercises 94
Lab 5 Exercises 95
Lab 6 Exercises 95
Lab 7 Exercises 95
Lab 8 Exercises 95
Lab 9 Exercises 96
Lab 10 Exercises 96
Lab 11 Exercise 96
Lab 12 Exercise 96
6. SAMPLE EXAM PAPER …………………………………………………………… 93
1. An Overview
1.1 Preface
Welcome to the module of Object Oriented Programming (OOP) and Design. This module aims to provide:
· An introduction to the concepts of object orientation using C++.
· An opportunity to enable students to re-use classes from the C++ libraries provided.
· The techniques to design and develop a software using UML (Unified Modeling Language).
It is hoped the this module challenging, informative, relvant and enjoyable.
Any suggestions and evaluations about this module handbook and all other aspects of your learning experiences of this mudole over the coming semester will be warmly received and welcome.
Xiaohong Gao, module leader
Bounds Green, office 2C23
Telephone : 020 8411 2252
Email:
http://www.cs.mdx.ac.uk/staffpages/xiaohong/
1.2 The module teaching team
Member of staff
/Role
/Telephone
/Office
Dr. Xiaohong Gao
/Module Leader
LecturesLabs
Seminars /
x.gao
/2252
/ 2C23Mike Batchelor
/Labs,
Seminars /m.batchelor
/ /1.3 About this Handbook
This handbook is not a complete set of learning materials for the work in the module. In addition to handbook, there is a recommended core text, seminars, computer labs and lectures. Students need to make full use of all these learning resources, and beyond – using materials from object oriented programming and C++ programming books in the libraries (e.g. at Bounds Green), following up materials from lectures by readling, seminars and practical work in the labs and your own time.
1.4 Overall Learning Objectives of CMT2050
The learning objectives of a module are the things that you should be able to do at the end of module. The coursework and exams are the estimation methods to test whether you have achieved the objectives. On passing the module you will be confident at writing object oriented programs using C++ language.
At the end of module you will be able to:
· Describe the application of object oriented principles in the process of program design.
· Discuss and critique the implementation quality of a set of classes.
· Using C++ to write classes and libraries.
· Using UML to design a software system with object oritation.
1.5 Acknowlegements
This handbook has been built upon materials originally authored by Alastair Measures, Janet Rix, and many other members in CMT group. Their contributions are gratefully acknowledged. 2 Learning Unit Narrative (LUN) ---- Official Module Information
MODULE CODE CMT2050
TITLE OBJECT ORIENTED PROGRAMMING AND DESIGN
LEVEL 2
CREDIT POINTS 20
PRE-REQUISITE CMT1501 or equivalent
AIMS /CATALOGUE ENTRY
This module aims to deepen your understanding of object-oriented concepts. It introduces an abstract modelling notation (UML) and puts theory into practice with C++. The module is designed to enable the students to both reuse classes from the libraries provided and to design and develop new classes.
SYLLABUS
¨ data abstraction, abstract data types and class design.
¨ class design using a graphicak notation such as UML.
¨ classes; constructors, destructors, instances, default constructors
¨ methods / member functions, virtual functions, pure and null functions
¨ data types; public, private and protected
¨ class hierarchies; inheritance, overloading, polymorphism
¨ container classes, ownership
¨ friend functions and friend classes.
¨ templates and template libraries
LEARNING OUTCOMES
At the end of this module you should be able to:-
Knowledge
¨ explain the software engineering issues and objectives leading to object orientation.
¨ explain the principles of encapsulation, inheritance and polymorphism.
¨ describe the application of object oriented principles in the process of program design.
¨ explain the object oriented features and syntax of C++.
¨ design and analysis an object-oriented software using UML.
LEARNING OUTCOMES -- SKILLS
Cognitive Skills
¨ discuss and critique the design quality of a set of classes expressed in UML.
¨ discuss and critique the implementation quality of a set of classes implemented in C++.
Subject Specific Skills
¨ use C++ to write classes.
¨ use software tools to build programs from re-usable components.
¨ Implement an object-oriented design with appropriate C++ features.
¨ Express the design of a class library in a clear and systemaatic manner using UML.
Transferable Skills
¨ working together with peers in preparing a group project report and presentation.
TEACHING AND LEARNING STRATEGIES
¨ Weekly lectures will deliver theory and principles with the aid of examples.
¨ Weekly seminars will build on the lectures with practical design exercises and group problem solving.
¨ Weekly supervised laboratory sessions will support students to strengthen their programming skills.
¨ Weekly self-study will be used for reading, studying the examples provided and completing assessed tasks.
LEARNING MATERIALS
Core Texts
¨ Jo Ann Smith, DEVELOPING PROJECTS USING OBJECT ORIENTED C++. International Thomson Publishers, 1999. ISBN 0-7600-1107-9.
Additional Texts
¨ H. M. Deitel and P. J. Deitel, C++ How to Program, 2/e. Prentice Hall, 1998. ISBN 0-13-528910-6
¨ R. C. LEE and W. M. Tepfenhart, UML and C++, A Protical Guide to Object_Oriented Development, 2nd ed., Prentice Hall, 2001. ISBN 0-13-029040-8.
ASSESSMENT SCHEME
Unseen Examination 40 % 3 questions from 5
Coursework 20 % Short Programs
Coursework 20 % Individual Project
Coursework 20 % Group Project
LEARNING UNIT CONTACT DURATIONS PER WEEK
Lecture 1:30
Seminars 1:00
Laboratory 1:30
Total Study Hours per Semester 180:00
Coursework
For this module: the coursework forms 60% of the assessment, relative to the exam which forms the remaining 40%. This recognises and rewards the higher level of effort that the coursework for this module demands.
The coursework for this module includes several parts: short programming tasks, a group project and an individual project. Students are required to attempt all three parts. Each of the three parts of the coursework accounts for one third of the coursework marks.
The Logbook
The logbook must have a copy of the “logbook cover sheet” [copy from next page] attached to the outside of the front cover. Do remember to fill in all the necessary details on the cover sheet.
The logbook should accumulate marked copies of your short programming tasks and individual projects. It is regarded as normal to have several versions of the same task as your skills improve in the light of feedback from your tutor.
Your programs and diagrams should be printed out, glued in and signed off (by your tutor) at the earliest opportunity. Please note that marks cannot be awarded without evidence (paper copies) of the work. This applies no matter what has been lost, stolen or vomitted upon by the dog!. Your programs and diagrams should be printed out, glued in and signed off (by your tutor) at the earliest opportunity.
The logbooks should be submitted to the student office before the end of the semester.
Please note that work contained in your logbook is not marked after you submit it to the student office at the end of the semester. After the end of the semester: the logbooks are needed for quality assurance purposes; such as checking the quality and consistency of marking. This checking is done by internal and external moderators.
Web Pages
Using the module home page you will be able to access documents detailing each piece of coursework you are required to do.
Each document will supply:
Cover Page: when relevant
The Task: exactly what you are being asked to provide.
The Learning Objective: why this tasks is a good thing to do.
Guidance on Deliverables: advice and guidance to help you.
The Marking Criteria: how a grade is decided.
The Deadline: when it should be done by.
5
CMT 2050:
Object Oriented Programming and Design
Semester 2, 2001/2002 Logbook Cover Page
DEADLINE: 3:00pm, 13th May 2002
Family Name
First Name
Student Number
Marks for the Coursework
/Grade
/ Lab tutor Signature / Grade / Lab Tutor SignatureShort 1 / Individual project
Short 2
Short 3
/ Group ProjectModule Leader: Dr. Xiaohong Gao
School of Computing Science
Bounds Green
Email:
Ext: 2252
Room: 2C23
The short programming tasks
These tasks are intended to develop your understanding of the constructs and techniques introduced in lectures. You should complete each, and get it assessed in your programming laboratory, before moving on to the next.
These tasks should be demonstrated and marked in the programming laboratory time. You may get a particular task assessed more than once, if it was not up to the standard required originally. Your tutor can explain any problems on screen or when it is assessed. You may also be asked questions about your program, or be asked to make changes to prove that you understand it. On satisfactory completion: you should printout a copy of the program and glue it into a logbook. The tutor must also make a note on their master mark sheet and initial each page of your program, and also sign your logbook cover sheet appropriately.
There will be a number of these “Short Programming Tasks” and they will be available on the module web pages, complete with marking criteria et cetera.
The Individual Project
These projects are intended to allow you demonstrate your understanding and capability in developing software using the constructs and techniques covered by this module.
You should choose one of the topics and develop your project based around it. If there is a different topic which interests you and is of similar complexity to the ones listed then you may attempt it; but only with the agreement of your tutor and lecturer. The purpose of requiring such agreement is to prevent students attempting projects which are too ambitious or that risk taking up too much of their time. If you have a topic in mind then please type up an outline description of the topic and show it to you tutor and then to your lecturer.