COEN 244 - 3 - Introduction To Classes and Object
COEN 244 - 3 - Introduction To Classes and Object
3
Introduction to
Classes and
Objects
3.1 Introduction
Programming languages may be classified into
two categories,
. Procedural languages :
Focus is on actions ( verbs), Ex: walking,
running. Ex. languages: C, Pascal.
Object-0riented languages:
- Function main
- One or more classes
Each class consists of two parts:
1. Class definition:
- Define data members
- Prototypes of member functions
2. Class implementation
- It gives implementation of
member functions
Class Members
Attributes
Exist throughout the life of the object
Represented as data members
Variables in a class definition
Local variables
Variables declared in a function definitions body
Cannot be used outside of that function body
Access-specifier: private
Makes a data member or member function accessible only
to member functions of the class
private is the default access for class members
Data hiding
Access-specifier: public
A data member or member function will be accessible also
to the clients of the class
Driver files
Program used to test software (such as classes)
Contains a main function so it can be executed
1 //
Fi g. 3. 11: Gr adeBook. h
Outline
6 usi ng st d: : st r i ng;
7
8 //
fig03_11.cpp
9 cl ass Gr adeBook
10 {
11 publ i c :
12
Gr adeBook( st r i ng ) ;
//
13
14
15
//
//
//
16 pr i vat e:
17
st r i ng cour seName; / /
18 }; / /
Outline
GradeBook implementation is
placed in a separate source-code file
fig03_12.cpp
(1 of 2)
Include the header file to access
the class name GradeBook
Outline
10
fig03_12.cpp
(2 of 2)
Outline
11
fig03_13.cpp
(1 of 1)
12
13