Chapter11 - C++ Programming: Program Design Including Data...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction C++ Programming: Program Design Including Data Structures, Fourth Edition 2 Objectives In this chapter, you will: Learn about classes Learn about private , protected , and public members of a class Explore how classes are implemented Examine constructors and destructors Learn about the abstract data type (ADT) C++ Programming: Program Design Including Data Structures, Fourth Edition 3 Objectives (continued) Explore how classes are used to implement ADTs Learn about information hiding Explore how information hiding is implemented in C++ Learn about the static members of a class C++ Programming: Program Design Including Data Structures, Fourth Edition 4 Classes Class : collection of a fixed number of components (members) Definition syntax: Defines a data type, no memory is allocated Dont forget the semicolon after closing brace C++ Programming: Program Design Including Data Structures, Fourth Edition 5 Classes (continued) Class member can be a variable or a function If a member of a class is a variable It is declared like any other variable In the definition of the class You cannot initialize a variable when you declare it If a member of a class is a function Function prototype is listed Function members can (directly) access any member of the class C++ Programming: Program Design Including Data Structures, Fourth Edition 6 Classes (continued) Three categories of class members private (default) Member cannot be accessed outside the class public Member is accessible outside the class protected C++ Programming: Program Design Including Data Structures, Fourth Edition 7 Classes (continued) private members, cant be accessed from outside the class const : formal parameter cant modify the value of the actual parameter These functions cannot modify the member variables of a variable of type clockType C++ Programming: Program Design Including Data Structures, Fourth Edition 8 Unified Modeling Language Class Diagrams +: member is public-: member is private #: member is protected C++ Programming: Program Design Including Data Structures, Fourth Edition 9 Variable (Object) Declaration Once a class is defined, you can declare variables of that type clockType myClock; clockType yourClock; A class variable is called a class object or class instance C++ Programming: Program Design Including Data Structures, Fourth Edition 10 Accessing Class Members Once an object is declared, it can access the public members of the class Syntax: The dot ( . ) is the member access operator If object is declared in the definition of a member function of the class , it can access the public and private members C++ Programming: Program Design Including Data Structures, Fourth Edition 12 Built-in Operations on Classes Most of C++s built-in operations do not apply...
View Full Document

This note was uploaded on 10/28/2010 for the course CS 2380 taught by Professor Chen during the Fall '05 term at Texas Pan American.

Page1 / 77

Chapter11 - C++ Programming: Program Design Including Data...

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

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