Starting Out with C++: Early Objects 5th Edition

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Lesson 13 Introduction to Classes CS1 Lesson Introduction to Classes1.
Chapter 7: User-Defined Functions II
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Chapter 7: Introduction to Classes and Objects
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 10 Structured Data.
Chapter 11: Structured Data. Slide Introduction An array makes it possible to access a list or table of data of the same data type by using a single.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 10: Records ( struct s)
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
1 Chapter 13 Introduction to Classes. 2 Topics 12.1 Procedural and Object-Oriented Programming 12.2 Introduction to Classes 12.3 Defining an Instance.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 11 Structured Data.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 7: Introduction.
Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified.
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
Structured Data and Classes Chapter 7. Combining Data into Structures Structure: C++ construct that allows multiple variables to be grouped together Structure.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
Chapter 7 A Data Types – Structures Structures Structure: C++ construct that allows multiple variables to be grouped together Structure Declaration.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 12 Introduction to Classes.
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
Structured Data and Classes
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 11: Structured Data.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 11: Structured Data.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
C Programming Structured Data.
1 1  Lecture 11 – Structured Data FTMK, UTeM – Sem /2014.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7. 12: Structures Starting Out with C++ Early Objects Eighth.
Chapter Structured Data 11. Combining Data into Structures 11.2.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++
Pointer to an Object Can define a pointer to an object:
Procedural and Object-Oriented Programming
Chapter 7: Introduction to Classes and Objects
11 Chapter Structured Data
Chapter 7: Introduction to Classes and Objects
Abstract Data Types Programmer-created data types that specify
Chapter 7: Introduction to Classes and Objects
Chapter 11: Structured Data.
Introduction to Classes
Chapter 7: Introduction to Classes and Objects
Chapter 7: Introduction to Classes and Objects
Chapter 7: Introduction to Classes and Objects
Introduction to Object-oriented Programming
Data Types – Structures
Data Types – Structures
Introduction to Classes
Chapter 11: Structured Data.
Classes and Objects.
Standard Version of Starting Out with C++, 4th Edition
Lecture 8 Object Oriented Programming (OOP)
Programming Fundamental
Presentation transcript:

Starting Out with C++: Early Objects 5th Edition Chapter 7 Structured Data and Classes Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved

Topics 7.1 Combining Data into Structures 7.2 Accessing Structure Members 7.3 Initializing a Structure 7.4 Nested Structures 7.5 Structures as Function Arguments 7.6 Returning a Structure from a Function 7.7 Unions 7.8 Abstract Data Types 7.9 Object-Oriented Programming © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 2

Topics (Continued) 7.10 Introduction to Classes 7.11 Introduction to Objects 7.12 Defining Member Functions 7.13 Design Considerations 7.14 Using a Constructor with a Class 7.15 Overloading Constructors 7.16 Destructors 7.17 Input Validation Objects 7.18 Using Private Member Functions © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 3

7.1 Combining Data into Structures Structure: C++ construct that allows multiple variables to be grouped together Structure Declaration Format: struct structure name { type1 field1; type2 field2; … typen fieldn; }; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 4

Example struct Declaration struct Student { int studentID; string name; short year; double gpa; }; structure tag structure members Notice the required ; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 5

struct Declaration Notes struct names commonly begin with an uppercase letter Multiple fields of same type can be in a comma-separated list string name, address; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 6

Defining Structure Variables struct declaration does not allocate memory or create variables To define variables, use structure tag as type name Student s1; studentID name year gpa s1 © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 7

7.2 Accessing Structure Members Use the dot (.) operator to refer to members of struct variables getline(cin, s1.name); cin >> s1.studentID; s1.gpa = 3.75; Member variables can be used in any manner appropriate for their data type © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 8

Displaying struct Members To display the contents of a struct variable, you must display each field separately, using the dot operator Wrong: cout << s1; // won’t work! Correct: cout << s1.studentID << endl; cout << s1.name << endl; cout << s1.year << endl; cout << s1.gpa; See pr7-01.cpp and pr7-02.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 9

7.3 Initializing a Structure Cannot initialize members in the structure declaration, because no memory has been allocated yet struct Student // Illegal { // initialization int studentID = 1145; string name = "Alex"; short year = 1; float gpa = 2.95; }; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 10

Initializing a Structure (continued) Structure members are initialized at the time a structure variable is created Can initialize a structure variable’s members with either an initialization list a constructor © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 11

Using an Initialization List An initialization list is an ordered set of values, separated by commas and contained in { }, that provides initial values for a set of data members {12, 6, 3} // initialization list // with 3 values © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 12

More on Initialization Lists Order of list elements matters: First value initializes first data member, second value initializes second data member, etc. Elements of an initialization list can be constants, variables, or expressions {12, W, L/W + 1} // initialization list // with 3 items © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 13

Initialization List Example Structure Declaration Structure Variable struct Dimensions { int length, width, height; }; Dimensions box = {12,6,3}; box length 12 width 6 height 3 © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 14

Partial Initialization Can initialize just some members, but cannot skip over members Dimensions box1 = {12,6}; //OK Dimensions box2 = {12,,3}; //illegal © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 15

Problems with Initialization List Can’t omit a value for a member without omitting values for all following members Does not work on most modern compilers if the structure contains any string objects Will, however, work with C-string members © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 16

Using a Constructor to Initialize Structure Members A constructor is a special function that can be a member of a structure It is normally written inside the struct declaration Its purpose is to initialize the structure’s data members © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 17

Using a Constructor (continued) Unlike most functions, a constructor is not called; instead, it is automatically invoked when a structure variable is created The constructor name must be the same as the structure name (i.e. the struct tag) The constructor must have no return type © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 18

A Structure with a Constructor struct Dimensions { int length, width, height; // Constructor Dimensions(int L, int W, int H) {length = L; width = W; height = H;} }; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 19

Passing Arguments to a Constructor Create a structure variable and follow its name with an argument list Example: Dimensions box3(12, 6, 3); © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 20

Default Arguments A constructor may be written to have default arguments struct Dimensions { int length, width, height; // Constructor Dimensions(int L=1, int W=1, int H=1) {length = L; width = W; height = H;} }; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 21

Omit () when no arguments are used Examples //Create a box with all dimensions given Dimensions box4(12, 6, 3); //Create a box using default value 1 for //height Dimensions box5(12, 6); //Create a box using all default values Dimensions box6; See pr7-03.cpp Omit () when no arguments are used © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 22

7.4 Nested Structures A structure can have another structure as a member. struct PersonInfo { string name, address, city; }; struct Student { int studentID; PersonInfo pData; short year; double gpa; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 23

Members of Nested Structures Use the dot operator multiple times to dereference fields of nested structures Student s5; s5.pData.name = "Joanne"; s5.pData.city = "Tulsa"; See pr7-04.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 24

7.5 Structures as Function Arguments May pass members of struct variables to functions computeGPA(s1.gpa); May pass entire struct variables to functions showData(s5); Can use reference parameter if function needs to modify contents of structure variable © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 25

Notes on Passing Structures Using a value parameter for structure can slow down a program and waste space Using a reference parameter speeds up program, but allows the function to modify data in the structure To save space and time, while protecting structure data that should not be changed, use a const reference parameter void showData(const Student &s) // header See pr7-05.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 26

7.6 Returning a Structure from a Function Function can return a struct Student getStuData(); // prototype s1 = getStuData(); // call Function must define a local structure for internal use to use with return statement © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 27

Returning a Structure Example Student getStuData() { Student s; // local variable cin >> s.studentID; cin.ignore(); getline(cin, s.pData.name); getline(cin, s.pData.address); getline(cin, s.pData.city); cin >> s.year; cin >> s.gpa; return s; } See pr7-06.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 28

7.7 Unions Similar to a struct, but Declared using key word union all members share a single memory location (which saves space) only 1 member of the union can be used at a time Declared using key word union Otherwise the same as struct Variables defined and accessed like struct variables © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 29

Example union Declaration union WageInfo { double hourlyRate; float annualSalary; }; union tag union members See pr7-07.cpp Notice the required ; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 30

Anonymous Union A union without a tag: With no tag you cannot create additional union variables of this type later Allocates memory at declaration time Refer to members directly without dot operator See pr7-08.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 31

7.8 Abstract Data Types A programmer-created data type that specifies legal values that can be stored operations that can be done on the values The user of an abstract data type does not need to know any implementation details (e.g., how the data is stored or how the operations on it are carried out) © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 32

Abstraction and Data Types Abstraction: a definition that captures general characteristics without details Ex: abstract triangle is a 3-sided polygon. A specific triangle may be scalene, isosceles, or equilateral Data Type: defines the kind of values that can be stored in a variable and the operations that can be performed on it © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 33

7.9 Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-Oriented programming is based on the data and the functions that operate on it. Objects are instances of Abstract Data Types, or ADTs. © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 34

Limitations of Procedural Programming Use of global data may allow data corruption Programs are often based on complex function hierarchies difficult to understand and maintain difficult to modify and extend easy to break © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 35

Object-Oriented Programming Terminology class: similar to a struct Allows bundling of related variables (member data) and the functions that operate on them (member functions) Describes the properties that all instances of the class will have object: an instance of a class, in the same way that a variable can be an instance of a struct © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 36

More Object-Oriented Programming Terminology attributes: member data of a class methods or behaviors: member functions of a class data hiding: restricting access to certain members of an object © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 37

Public Interface Class objects are accessed from outside the class via a public interface This is done by allowing some of the member functions to be called from outside the class Normally, all the class’s member variables are accessed only through these “public” functions This provides some protection from data corruption © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 38

7.10 Introduction to Classes A class declaration describes the member variables and member functions that its objects will have It is a pattern for creating objects Class Declaration Format: class className { declaration; }; Notice the required ; © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 39

Access Specifiers Used to control access to members of the class. Each member is declared to be either public: can be accessed by functions outside of the class or private: can only be called by or accessed by functions that are members of the class © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 40

Class Example class Square { private: int side; public: void setSide(int s) { side = s; } int getSide() { return side; } }; Access specifiers © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 41

More on Access Specifiers Can be listed in any order in a class Can appear multiple times in a class If not specified, the default is private © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 42

7.11 Introduction to Objects An object is an instance of a class Defined like structure variables Square sq1, sq2; Access members using dot operator sq1.setSide(5); cout << sq2.getSide(); Compiler error if attempt to access private member using dot operator See pr7-09.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 43

7.12 Defining Member Functions Member functions are part of a class declaration Can place entire function definition inside the class declaration or Can place just the prototype inside the class declaration and write the function definition after the class © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 44

Defining Member Functions Inside the Class Declaration Member functions defined inside the class declaration are called inline functions Only very short functions, like the one below, should be inline functions int getSide() { return side; } © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 45

Inline Member Function Example class Square { private: int side; public: void setSide(int s) { side = s; } int getSide() { return side; } }; inline functions © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 46

Defining Member Functions After the Class Declaration To define a member function after the class declaration Put a function prototype in the class declaration In the function definition, precede function name with class name and scope resolution operator (::) int Square::getSide() { return side; } See pr7-10.cpp and pr7-11.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 47

Tradeoffs of Inline vs. Regular Member Functions When a regular function is called, control passes to the called function the compiler stores return address of call, allocates memory for local variables, etc. Code for an inline function is copied into the program in place of the call larger executable program, but no function call overhead, possibly faster execution © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 48

7.13 Design Considerations Class should be designed to provide functions to store and retrieve data In general, I/O should be done by functions that use class objects, rather than by class member functions (Exceptions can occur, as with a class designed to display a menu) © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 49

More Design Considerations Separating class declaration, member function definitions, and program that uses the class into separate files is considered good design © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 50

Using Separate Files Place class declaration in a header file that serves as the class specification file. Name the file classname.h (for example, Square.h) Place member function definitions in a class implementation file. Name the file classname.cpp (for example, Square.cpp)This file should #include the class specification file. Programs that use the class must #include the class specification file and be compiled and linked with the class implementation file. See pr7-12.cpp, rectangle.cpp, and rectangle.h © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 51

7.14 Using a Constructor with a Class As with a structure, a constructor can be used to initialize data members of a class Must be a public member function Must be named the same as the class Must have no return type Is called automatically when an object of the class is created © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 52

The Default Constructor Constructors can have any number of parameters, including none A default constructor is one that takes no arguments either due to No parameters or All parameters have default values © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 53

Default Constructor Example class Square { private: int side; public: Square() // default { side = 1; } // constructor // Other member // functions go here }; Has no parameters © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 54

Another Default Constructor Example class Square { private: int side; public: Square(int s = 1) // default { side = s; } // constructor // Other member // functions go here }; Has parameter but it has a default value © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 55

Invoking a Constructor Invoking a constructor for a class object is done just like invoking a constructor for a structure variable To create an object using the default constructor, use no argument list and no () Square square1; To create an object using a constructor that has parameters, include an argument list Square square1(8); See pr7-13.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 56

7.15 Overloading Constructors A class can have > 1 constructor Overloaded constructors in a class must have different parameter lists Square(); Square(int); Only one default constructor is allowed © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 57

Member Function Overloading Non-constructor member functions can also be overloaded void setSide(); void setSide(int); Must have unique parameter lists (as with constructors) See pr7-14.cpp and sale.h © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 58

7.16 Destructors Public member function automatically called when an object is destroyed Destructor name is ~className, e.g., ~Square Has no return type Takes no arguments Only 1 destructor is allowed per class (i.e., it cannot be overloaded) See pr7-15.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 59

7.17 Input Validation Objects Objects can be designed to validate user input to ensure acceptable menu choice to ensure a value is in range of valid values etc. See pr7-16.cpp, CharRange.cpp, and CharRange.h © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 60

7.18 Using Private Member Functions A private member function can only be called by another member function of the same class It is used for internal processing by the class, not for use outside of the class See pr7-17.cpp © 2006 Pearson Education. All Rights Reserved Chapter 7 Starting Out with C++: Early Objects 5/e slide 61

Starting Out with C++: Early Objects 5th Edition Chapter 7 Structured Data and Classes Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved