Information systems 28
[pic]
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
3 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: x.gao@mdx.ac.uk
22 The module teaching team
| | | | | |
|Member of staff |Role |Email |Telephone |Office |
|Dr. Xiaohong Gao |Module Leader | | | |
| |Lectures |x.gao |2252 |2C23 |
| |Labs | | | |
| |Seminars | | | |
|Mike Batchelor |Labs, |m.batchelor | | |
| |Seminars | | | |
27 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. 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.
[pic]
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 Signature |
|Short 1 | | |Individual project | | |
|Short 2 | | | | | |
|Short 3 | | |Group Project | | |
Module Leader: Dr. Xiaohong Gao
School of Computing Science
Bounds Green
Email: x.gao@mdx.ac.uk
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.
There will be a number of suggested project outlines available on the module web pages together with marking criteria et cetera.
The Group Project
This requires students to work together in teams. There should be between three and five students in a team. The project team should look at the task together and agree to delegate specific tasks to individual members of the team. The team should work at providing an analysis of the problem, designing a solution and providing samples of what the code would look like. Time will be made available during seminars for teams to meet and discuss their project.
Each group should deliver a report to the student office and after that they will be required (as a group) to deliver a five minute presentation on their report and recommendations. This presentation will be made in seminar time and will end with time for questions and answers.
The details of this assignment will be on the module web page.
Short Programming Task 1 ---- to be assessed in Week 3/4 (7% of total marks)
Using Video class, create a Nurse class to keep nurses’ records. The Nurse class should include at least the following data members:
• name
• gender
• age
• working place
• Rank (e.g., superintendent, junior, senior)
The main program (nursemain.cpp) should provide interface for inputting nurse’s data and outputting these data.
Guidance on Deliverables
• Pages 1-3: All of your source code (cpp and h files).
• All of your source code (cpp and h files) should have consistent indentation to a clear style.
• All program listings are to go into the students’ logbook.
The Marking Criteria (for short program task 1).
The following are indicative evidence for achieving the corresponding level. You must meet ALL the criteria for a level to have reached that level.
Q: Missing
• No demonstration given.
F: Fail
• The Nurse class is an exact copy of the (say) Video class.
• No additional data members and functions are provided.
• Test program fails to instantiated objects of the Nurse class.
• Test program does not attempt to call the requested member functions.
P: Pass
• Nurse class based on Video class with most of the additional data members
• Most of the member functions are provided as requested
• An object of class Nurse is instantiated by the test program
• Test program calls most of the requested member functions.
• Comments are relevant to the additional code.
• Student demonstrates understanding of classes, objects, data members and member functions.
M: Merit
• Nurse class based on Video class with all additional data members
• Separate member functions are provided to (e.g., change working place, change rank, display nurse name, display working place, display rank ).
• An object of class of Nurse is instantiated by the test program.
• Test program calls all the requested member functions.
• Comments are relevant to the additional code.
• Student demonstrates understanding of classes, objects, data members and member functions.
D: Distinction
• In addition to the criteria of Merit Level:
• Data validation is performed by the set functions
• Two constructors (including the default) should be supplied.
• The new set member functions are called by the constructors and other relevant functions.
The Deadline
This task should be completed and marked by the end of week 3/ 4 !
Task 2: ---- to be assessed by Week 6 (7%of total marks)
Modify the following class for Airplane to include at least:
• Two more constructors.
• Declare “type” using pointer.
• Add a data member “date” using pointer type (e.g., 01-02-1950) to indicate the date when the airplane was registered.
(the original 3 sample files (airplane.h, airplane.cpp, main.cpp ) are in
L:\2001-02\Cmt2050\week2)
//ariplane.h
#ifndef AIRPLANE_H
#define AIRPLANE_H
class Airplane
{
public:
Airplane();
void set_type(char*);
void set_current_speed(double);
void set_max_speed(double);
const char* get_type();
double get_current_speed();
double get_max_speed();
private:
char type[50];
double current_speed;
double max_speed;
};
Task 2 Marking Scheme
The following are indicative evidence for achieving the corresponding level. You must meet ALL the criteria for a level to have reached that level.
Q: Missing
• No demonstration given.
• Program code not handed in to student office.
F: Fail
• Program is exactly the same as in week 2 directory at L drive.
P: Pass
• Two constructors are given.
• Airplane type is declared as pointer and implemented using new or delete where appropriate.
M: Merit
• Two constructors are given.
• Pointer types are given to the Airplane type.
• new and delete are used properly to reflect pointer types in all the places where type is given new values.
D: Distinction
• In addition to the criteria for Merit,
• Methods should be marked const where appropriate.
• A data member date is given as pointer type and is properly reflected using new and delete where appropriate.
• A member function is created to access date data member.
• A reasonable interface should be given for changing current speed.
Short programming task 3 ---- to be marked in week 9 (10% of total mark)
Create a list of student records. The student class should include the following data members:
• name
• age
• gender
• date of enrollment
• degree to study (e.g., BSc, fundation, HND)
Guidance on Deliverables
• The date of enrollment should form a separate class and include at least
➢ day
➢ month
➢ year
• An array of student records should be created.
Task 3 Marking Scheme
The following are indicative evidence for achieving the corresponding level. You must meet ALL the criteria for a level to have reached that level.
Q: Missing
• No demonstration given.
• Program code not handed in to student office.
F: Fail
• Two classes with some (public) methods and (private) member variables.
• Test program does not attempt to call the requested member functions.
• Some comments at the head of each source file.
P: Pass
• A date class contains appropriate member variables.
• A Student class contains appropriate member variables.
• Implement a reasonable set of "set" and "get" functions on each class.
• Implement at least a default constructor for each class.
• An object of stuRecord class is created by the test program and includes date class.
• Test program does attempt to call the requested member functions.
• Each class has a separate header (.h) file and source code (.cpp) file.
M: Merit
• An array of student records is created.
• Test functions create an instance for input before outputting it.
• Each implemented member function should have a descriptive comment.
• Student demonstrates understanding of composition and constructors.
D: Distinction
• Data validation is performed by all the set functions
• Two constructors (including the default) should be supplied for each class.
• The "set" methods are called by the constructors and other relevant functions.
• Methods should be marked const where appropriate.
• A reasonable interface is created.
Programming project ---- to be marked in week 12 (16% of total marks)
A programming project should be chosen to demonstrate your understanding of and ability to use the different constructs and concepts covered in the course.
The programming project should be demonstrated and marked in the programming labs. You are expected to develop your program in stages – modifying your earlier version to include extra functionality.
A print out of all project files and associated documentation together with the program files for each of the short programming tasks, must be handed in to the student office by 3:00pm, Monday 13th May.
Suggested projects are given below. You choose one of these projects (only one).
• Design and implement a set of classes to print out Student records in an alphabetical order by last name. The program should include Part-time students class and full time student class.
❑ Part time student might have working place, time to study, e.g., evening, one day per week, years to finish degree (4 years, 6 years).
❑ Full time students might have A-level, GCSE results.
• Design and implement a set of classes to record residencies for a district council. The program should print out the residencies in an alphabetical order by last name.
❑ Each family might have father, mother, and children.
❑ Father or mother should have occupation, working place.
❑ Children should have name of school.
• Design and implement a set of classes for a vehicle registration and print out all the registered vehicle in an alphabetical by their plates.
❑ Vehicles at least include cars and motorbike.
❑ Each vehicle should have model, type, etc..
❑ Each registration should include the owner, owner’s address, registration number, price of the vehicle.
Programming project Marking Scheme
The following are indicative evidence for achieving the corresponding level. You must meet ALL the criteria for a level to have reached that level.
Q: Missing
No demonstration given
Program code not handed in to student office
F: Fail
The class or set of classes does not fulfill one of the project outlines.
Test program fails to instantiate objects of the new classes.
Test program does not successfully call member functions of the new classes.
P: Pass
• Coherent sets of classes, which include derived classes, have been designed to fulfil the chosen project outline.
The test program provides a basic interface to the new classes, with a limited range of functions suitable for the chosen project.
The test program instantiates an object of at least one of the new classes.
Test program successfully calls several of the member functions for the new classes.
Comments are relevant to the code
Student demonstrates understanding of the classes presented.
M: Merit
A coherent set of classes, which includes derived classes, has been designed to fulfil the chosen project outline.
At least, 7 files (4 .cpp files, 3 .h files) are given, i.e, two inherited classes are given.
The test program provides a sensible user interface to the new classes, with a good range of functions suitable for the chosen project.
The test program instantiates objects of relevant classes.
Test program is capable of successfully calling all of the member functions for the new classes.
Comments are relevant to the code
The student has demonstrated understanding and sensible use of most of the following techniques:
Base classes, Inherited classes and Inheritance. Const functions and data members. Private, protected and public access mechanisms.
D: Distinction
All evidence required as for Merit level above and:
The test program provides a comprehensive user interface to the new classes, with a wide range of functions suitable for the chosen project.
The student has also demonstrated understanding and sensible use at least FOUR of the following techniques:
Composition, friendship, overloading, copy constructor, dynamic memory, operator overloading, inline function.
• File input/output is used with relevant data files.
OR
• 2 or more aspect of complexity and new techniques implemented.
Group Project (10% for presentation and 10% for report )
In your seminar class you should form into groups with 2 to 4 students, time will be made available from Week 7 (March 18) for the group to work together during time tabled seminar sessions. As a group you must complete the assigned task, prepare a written report, and make a presentation outlining your recommendations to the rest of the seminar class.
The tasks (choose one) :
1. Use UML to design a Library Information System with facilities of
❑ Borrowing including fines for over due items
❑ Returning
❑ Indexing new items/books
❑ Deleting some old items/books
❑ Providing electronic information
2. Use UML to design a Travel Agency System with facilities of
❑ Holiday/Air ticket booking via interviewing
❑ Holiday/Air ticket booking via telephone
❑ Holiday/Air ticket booking via internet
3. Use UML to design a Banking System with facilities of
❑ Personal account including current and save accounts
❑ Telephone banking
❑ Personal information
The written report must include the following:
A list of group members names and student numbers.
An outline of the tasks allocated to each person at different stages
(e.g. analysis, design , written report, presentation, etc).
– Signed and agreed by all team members.
Details of group meetings (minutes of meetings).
Design of the system using UML.
➢ Identifying nouns for the system via interviewing or other means.
➢ Identifying classes
➢ Some class diagrams
➢ Some use case diagrams
➢ Full class diagram using UML notation
Source code for selected examples of member functions
Appendix of information collected if there are any.
The overall grade will be given on the basis of:
the degree to which all members of the group have contributed to the task,
and how well the group have worked together (allocated tasks, etc).
the quality of the report
the quality of the presentation
The presentation will be in the seminar of week 11 and will last about 10-15 mins. After the presentation there will be a question and answer session. Every member of the group will be expected to answer at least one question.
Each group will be given a grade. Every member of the group will thus get the same grade. The exception to this is that any individual who does not attend the presentation or sign the task outline will be given a Q grade.
The report will be handed in to the Student Office with LogBook by May 13, Monday. Each member of the group will have a copy of the report in his/her logbook.
CMT2050: Presentation marking guidelines
The following are intended to give an idea of the level of presentation skill required to get a particular grade. They describe the minimum skill level to achieve the grade. They are just a guideline for the marker. If you make most of the points for a particular level, allowance may be made for other points. The marker’s decision is final.
Distinction
Talk well structured with clear sign-posting of sections
High quality visual aids (something special about them)
Highly enthusiastic – maintains interest throughout
Logical argument
Merit
Talk has structure (introduction, middle, end)
Good use of visual aids
Enthusiastic
Attempt at logical argument
Satisfactory
Attempt to structure talk – e.g. introduction but shaky on conclusion
Talk audible and understandable
Talk is on topic set
If problems with visual aids (eg blocked) notices
Winds up smoothly to time.
Good eye contact throughout
Pass
Little structure to talk
About topic set
No use of visual aids or poor quality visual aids (eg too small to read)
Occasionally halting delivery
Over runs on time and is cut short rather than winding up smoothly
Some eye contact
Referral
No structure
Only barely about topic
No use of visual aids
Inaudible for much of time
Over runs and continues for significant time after being wound up
No eye contact
Fail
Talk abandoned part way through
Inaudible
No visual aids used
Off topic
Q: Did not give a presentation (a fail grade)
Lecture Plan ---- CMT 2050
|Dates |Week |Title |Lab |Seminar |Week |
|Feb. 4 |1 |Object Oriented Programming (OOP) & |Build a project and |The cycle of Programming |1 |
|- Feb. 8 | |Borland C++ Builder 5 |short programming task 1 | | |
|Feb.11 |2 |Classes and Data Encapsulation |Classes and |exercises |2 |
|-Feb. 15 | | |short programming task 1 | | |
|Feb. 18 |3 |Abstractors and constrcutors |Constructors |Exercises |3 |
|- Feb. 22 | | |Short programming task 1 Marking | | |
|Feb. 25 |4 |Pointers (*) & Destrcutor (~) |Pointer & |Exercises |4 |
|- Mar. 1 | | |Short programming task 1 Marking | | |
|Mar. 4 |5 |Polymorphism |Function overloading |Exercises |5 |
|- Mar. 8 | | |Task 2 | | |
|Mar. 11 |6 |Composition and inheritance (1) |Composition |Exercises |6 |
|- Mar. 15 | | |Task 2 Marking | | |
|Mar. 18 |7 |OO Design using UML |Inheritance |Exercises |7 |
|- Mar. 22 | | |Task 3 |Introduction to group project | |
|Mar. 25 |E1 |Week 1 of Easter break | | |E1 |
|- Mar. 29 | | | | | |
|Apr. 1 |E2 |Week 2 of Easter Break | | |E2 |
|- Apr. 5 | | | | | |
| | | | | | |
|Apr. 8 |8 |Composition and inheritance (2) |Task 3 |Group project meeting |8 |
|- Apr. 12 | | | | | |
|Apr. 15 |9 |Static data members, methods, |Task 3 Marking |Group project meeting |9 |
|- Apr. 19 | |& Static binding and dynamic binding |Individual Project | | |
|Apr. 22 |10 |Advanced C++ Techniques (1) |Inline functions, friend functions |Group project presentation |10 |
|- Apr. 26 | | |Individual project |Marking | |
|Apr. 29 |11 |Advanced C++ Techniques (2) |Operator overloading |Group project presentation |11 |
|- May 3 | | |Individual project |Marking | |
|May 6 |12 |Revision |Individual project marking |Submission of Log-Book by |12 |
|- May 10 | | | |3:00pm, 13/05/2001 | |
3. Lectures
Lecture 1 Object-Oriented Programming (OOP)
1 Procedural Programming
• Programs ---- consist of modules, which are parts that can be designed, coded, and tested separately and then assembled.
• Procedural Programming (such as C language) ---- the modules are procedures.
• In C, a function is a procedure.
• C language is a procedural language in which a program’s modules are its functions.
• Designing a procedural program is known as top-down design.
• Example 1 ---- print out an integer number, a character, and a double number.
Figure 1.1 relationship between data and the functions in procedural programming.
2 Object-Oriented Programming
• Is another way of thinking about programming.
• The focus is on the relationship between data and tasks, rather than on a program’s tasks.
• A program contains objects that respond to messages sent to them.
• A message (or function call) is simply a request for the object to do something.
• In C++, you create objects that contain data and actions or behaviors that the object is capable of performing.
• These actions, called methods (or member functions), are implemented by writing functions that are part of object itself.
• Example 2 --- print out an integer number, a character, and a double number.
• In example 2, the relationship between data and the methods is built into the object itself.
• After an object named print_obj is created, it knows how to print_int(), print_char(), and print_double().
• Data are not passed to these methods.
• The object knows how to print the values of the data members that belong to the same object.
• E.g., print_obj.print_char() sends the print_char() message to the print_obj object.
• The print_obj object responses by printing the character stored in its data member.
Figure 2.1 Relationship between data and the methods in object-oriented programming.
Exercise:
1. Using an example to explain the differences between procedural programming and object-oriented programming.
Lecture 2 Classes and Data Encapsulation
2.1 Introduction
Object Oriented (OO) Programming is a data oriented approach to program design.
A major idea behind object orientation involves observing that programs attempt to simulate interactions with (and between) “things” in the real world.
An OO program is consisted of classes that are building blocks.
A class has a collection of member variables (fields to contain values).
A class also has a collection of methods (functions to carry out actions associated with the class).
Methods are also referred to as member functions.
An instance of a class is known as an object.
Classes are also known as abstract data types in object oriented terminology. These are data types that can be used almost anywhere that ordinary (atomic) data types like float can. Physical data types like int and float are already well known to the compiler; whereas classes we create are not.
An example of class:
| |
|class umbrella |
|{ |
|// DEFINE MEMBER VARIABLES WITH DATA TYPES |
|private: |
|float length; |
|float diameter; |
|float weight; |
| |
|// DEFINE PROTOTYPES FOR MEMBER FUNCTIONS |
|public: |
|void print_diameter ( ); |
|void print_area ( ); |
|}; |
2.2 Classes
A class is an abstract data type. An instance of a class is called an object.
In the same way that a function has a prototype and an implementation; a class has a definition, which specifies the interface and an implementation which codes the task.
A class definition has the general form:
| |
|class aclassname |
|{ |
|private: |
|// private member declarations (member variables) go here |
| |
|public: |
|// public member declarations (member functions) go here |
| |
|}; // NOTE: semicolon is needed |
The public section of the class definition marks out those parts which form the interface which can be used from elsewhere.
The private section of the class definition marks out those parts which are hidden members of the class and not available for external use.
The private and public sections do not need to be in a specific sequence; and, there can be many public and private sections within a class definition (though it is usually simpler to group items).
Essential good practice involves making all member variables private and most member functions public.
2.3 Example Program Using Classes
| |
|// program.cpp |
| |
|#include |
|#include "video.h" |
| |
|void main ( ) |
|{ |
|// Create an object |
|Video vid1; |
| |
|// Invoke various methods on the object |
|vid1.set_all ( "Titanic", "Cameron Co", 40); |
|cout ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- why are information systems essential
- introduction to information systems pdf
- information systems professional organization
- information systems in business organizations
- information systems impact on business
- information systems affect on business
- how information systems impact organizations
- information systems in organizations pdf
- information systems within an organization
- management information systems organization
- what is information systems pdf
- importance of information systems pdf