L03_classes

L03_classes - COMP152 Spring 2010 D.Y. Yeung C+ Classes...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Classes Nyhoff: 1-4 Deitel: 1,3,9-10 COMP152 Spring 2010 D.Y. Yeung
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline 2 Procedural vs. Object-Oriented Programming Basic OOP Private/public data and member functions Accessor and mutators Constructors Separate compilation and conditional compilation directives to avoid redundant declaration Constant member functions Operator overloading and friend Destructors Other issues Initializer Composition: objects as members of classes Using this pointer Static class members
Background image of page 2
Motivation Types such as int , double , and char are “dumb” objects. They can only answer one question: “What value do you contain?” 3!!! 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming Paradigm: Procedural Concept The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters 4
Background image of page 4
Procedural Concept - Problems Decoupled Data and Operations The resulting modular structure is oriented on the operations rather than the actual data The defined operations specify the data to be used. The design is: What data we have, and what operations we need to manipulate it? 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Concept (in C++) Objects of the program interact by sending messages to each other 6
Background image of page 6
Procedural vs. Object-Oriented Programming Procedural Object-oriented 7 Action -oriented – concentrates on the verbs Programmers : Identify basic tasks to solve problem Implement actions to do tasks as subprograms (procedures/ functions/subroutines) Group subprograms into programs/modules/libraries, together make up a complete system for solving the problem Focuses on the nouns of problem specification Programmers : Determine objects needed for problem Determine how they should work together to solve the problem Create types called classes with data members function members to operate on the data Instances of a type (class) are called objects
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Classes Classes allow you to build “smart” objects that can answer many questions (and perform various actions). “What is your temperature?” “What is your temperature in Fahrenheit?” “What is your humidity?” “Print your temperature in Kelvin.” Objects may send messages to each other, which in turn affect the operations of the objects. This leads to different outcomes of the program 8
Background image of page 8
OOD: Object-Oriented Design 9 Identify the objects in the problem's specification and their types Identify the operations or tasks to manipulate the objects FinancialAidAward amount source getAmount() getsource() display() setAmount() setSource() data operations Think of them as Containers
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
First Look at ADTs & their Implementation For a programming task we must identify The collection of data items Basic operations or algorithms to be performed on them The two taken together (data items & operations) form an Abstract Data Type (ADT) As an application developer, you do not need to worry about
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 106

L03_classes - COMP152 Spring 2010 D.Y. Yeung C+ Classes...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online