Presentation is loading. Please wait.

Presentation is loading. Please wait.

C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.

Similar presentations


Presentation on theme: "C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction."— Presentation transcript:

1 C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction

2 C++ Programming: Program Design Including Data Structures, Fourth Edition2 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)

3 C++ Programming: Program Design Including Data Structures, Fourth Edition3 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

4 C++ Programming: Program Design Including Data Structures, Fourth Edition4 Classes Class: collection of a fixed number of components (members) Definition syntax: −Defines a data type, no memory is allocated −Don’t forget the semicolon after closing brace

5 C++ Programming: Program Design Including Data Structures, Fourth Edition5 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

6 C++ Programming: Program Design Including Data Structures, Fourth Edition6 Classes (continued) Three categories of class members − private (default) Member cannot be accessed outside the class − public Member is accessible outside the class − protected

7 Chapter 9 Starting Out with C++: Early Objects 5/e slide 7 © 2006 Pearson Education. All Rights Reserved 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

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

9 Chapter 9 Starting Out with C++: Early Objects 5/e slide 9 © 2006 Pearson Education. All Rights Reserved 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

10 Chapter 9 Starting Out with C++: Early Objects 5/e slide 10 © 2006 Pearson Education. All Rights Reserved 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 ;

11 Chapter 9 Starting Out with C++: Early Objects 5/e slide 11 © 2006 Pearson Education. All Rights Reserved 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

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

13 Chapter 9 Starting Out with C++: Early Objects 5/e slide 13 © 2006 Pearson Education. All Rights Reserved 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

14 Chapter 9 Starting Out with C++: Early Objects 5/e slide 14 © 2006 Pearson Education. All Rights Reserved 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

15 Chapter 9 Starting Out with C++: Early Objects 5/e slide 15 © 2006 Pearson Education. All Rights Reserved #include using namespace std; // Circle class declaration class Circle {private: double radius; public: void setRadius(double r) { radius = r; } double getArea() { return 3.14 * pow(radius, 2); } }; int main(){ Circle sphere1, // Define 2 Circle objects sphere2; sphere1.setRadius(1); // This sets sphere1's radius to 1 sphere2.setRadius(2.5); // This sets sphere2's radius to 2.5 cout << "The area of sphere1 is " << sphere1.getArea() << endl; cout << "The area of sphere2 is " << sphere2.getArea() << endl; return 0; }

16 Chapter 9 Starting Out with C++: Early Objects 5/e slide 16 © 2006 Pearson Education. All Rights Reserved 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

17 Chapter 9 Starting Out with C++: Early Objects 5/e slide 17 © 2006 Pearson Education. All Rights Reserved #include using namespace std; class Circle{ private: double radius; public: void setRadius(double r) { radius = r; } }; int main(){ }

18 Chapter 9 Starting Out with C++: Early Objects 5/e slide 18 © 2006 Pearson Education. All Rights Reserved Problem: Update the program in the last slide: (1)Add a public function to compute the circle length. (2)Create an circle object with radius 3.0. (3)Output its length.

19 Chapter 9 Starting Out with C++: Early Objects 5/e slide 19 © 2006 Pearson Education. All Rights Reserved #include using namespace std; class Circle{ private: double radius; public: void setRadius(double r) { radius = r; } double length(){return 2.0*radius*3.1416;} }; int main(){ Circle c1; c1.setRadius(3.0); cout<<“Boundary Length is “<<c1.length(); return 0; }

20 C++ Programming: Program Design Including Data Structures, Fourth Edition20 Classes (continued) private members, can’t be accessed from outside the class const : formal parameter can’t modify the value of the actual parameter These functions cannot modify the member variables of a variable of type clockType

21 C++ Programming: Program Design Including Data Structures, Fourth Edition21 Unified Modeling Language Class Diagrams +: member is public -: member is private #: member is protected

22 C++ Programming: Program Design Including Data Structures, Fourth Edition22 Variable (Object) Declaration Once a class is defined, you can declare variables of that type clockTypemyClock; clockTypeyourClock; A class variable is called a class object or class instance

23 C++ Programming: Program Design Including Data Structures, Fourth Edition23 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

24

25 C++ Programming: Program Design Including Data Structures, Fourth Edition25 Built-in Operations on Classes Most of C++’s built-in operations do not apply to classes −Arithmetic operators cannot be used on class objects unless the operators are overloaded −You cannot use relational operators to compare two class objects for equality Built-in operations valid for class objects: −Member access (. ) −Assignment ( = )

26 C++ Programming: Program Design Including Data Structures, Fourth Edition26 Assignment Operator and Classes

27 C++ Programming: Program Design Including Data Structures, Fourth Edition27 Class Scope An object can be automatic or static A member of the class is local to the class You access a class member outside the class by using the class object name and the member access operator (. )

28 C++ Programming: Program Design Including Data Structures, Fourth Edition28 Functions and Classes Objects can be passed as parameters to functions and returned as function values As parameters to functions −Objects can be passed by value or by reference If an object is passed by value −Contents of data members of the actual parameter are copied into the corresponding data members of the formal parameter

29 C++ Programming: Program Design Including Data Structures, Fourth Edition29 Reference Parameters and Class Objects (Variables) Passing by value might require a large amount of storage space and a considerable amount of computer time to copy the value of the actual parameter into the formal parameter If a variable is passed by reference −The formal parameter receives only the address of the actual parameter

30 C++ Programming: Program Design Including Data Structures, Fourth Edition30 Reference Parameters and Class Objects (Variables) (continued) Pass by reference is an efficient way to pass a variable as a parameter −Problem: when passing by reference, the actual parameter changes when formal parameter changes −Solution: use const in the formal parameter declaration

31 C++ Programming: Program Design Including Data Structures, Fourth Edition31 Implementation of Member Functions Scope resolution operator

32 C++ Programming: Program Design Including Data Structures, Fourth Edition32 Implementation of Member Functions (continued)

33

34

35

36 C++ Programming: Program Design Including Data Structures, Fourth Edition36 Implementation of Member Functions (continued) Once a class is properly defined and implemented, it can be used in a program −A program that uses/manipulates the objects of a class is called a client of that class When you declare objects of the class clockType, every object has its own copy of the member variables ( hr, min, and sec ) Variables such as hr, min, and sec are called instance variables of the class −Every object has its own instance of the data

37 C++ Programming: Program Design Including Data Structures, Fourth Edition37 Accessor and Mutator Functions Accessor function: member function that only accesses the value(s) of member variable(s) Mutator function: member function that modifies the value(s) of member variable(s) Constant function: −Member function that cannot modify member variables −Use const in function heading

38 C++ Programming: Program Design Including Data Structures, Fourth Edition38 Order of public and private Members of a Class C++ has no fixed order in which you declare public and private members By default all members of a class are private Use the member access specifier public to make a member available for public access

39 C++ Programming: Program Design Including Data Structures, Fourth Edition39 Order of public and private Members of a Class (continued)

40 C++ Programming: Program Design Including Data Structures, Fourth Edition40 Order of public and private Members of a Class (continued)

41 C++ Programming: Program Design Including Data Structures, Fourth Edition41 Order of public and private Members of a Class (continued)

42 C++ Programming: Program Design Including Data Structures, Fourth Edition42 Constructors Use constructors to guarantee that data members of a class are initialized Two types of constructors: −With parameters −Without parameters (default constructor) The name of a constructor is the same as the name of the class A constructor has no type

43 C++ Programming: Program Design Including Data Structures, Fourth Edition43 Constructors (continued) A class can have more than one constructor −Each must have a different formal parameter list Constructors execute automatically when a class object enters its scope −They cannot be called like other functions −Which constructor executes depends on the types of values passed to the class object when the class object is declared

44 C++ Programming: Program Design Including Data Structures, Fourth Edition44 Constructors (continued)

45 Can be replaced with: setTime(hours, minutes, seconds);

46 C++ Programming: Program Design Including Data Structures, Fourth Edition46 Invoking a Constructor A constructor is automatically executed when a class variable is declared

47 C++ Programming: Program Design Including Data Structures, Fourth Edition47 Invoking the Default Constructor To invoke the default constructor: Example: clockType yourClock;

48 C++ Programming: Program Design Including Data Structures, Fourth Edition48 Invoking a Constructor with Parameters Syntax: The number of arguments and their type should match the formal parameters (in the order given) of one of the constructors −Otherwise, C++ uses type conversion and looks for the best match −Any ambiguity leads to a compile-time error

49 C++ Programming: Program Design Including Data Structures, Fourth Edition49 Constructors and Default Parameters If you replace the constructors of clockType with the constructor in Line 1, you can declare clockType objects with zero, one, two, or three arguments as follows: clockType clock1; //Line 2 clockType clock2(5); //Line 3 clockType clock3(12, 30); //Line 4 clockType clock4(7, 34, 18); //Line 5

50 C++ Programming: Program Design Including Data Structures, Fourth Edition50 Classes and Constructors: A Precaution If a class has no constructor(s), C++ provides the default constructor −However, object declared is still uninitialized If a class includes constructor(s) with parameter(s), but not the default constructor −C++ does not provide the default constructor

51 C++ Programming: Program Design Including Data Structures, Fourth Edition51 Arrays of Class Objects (Variables) and Constructors If a class has constructors and you declare an array of that class’s objects, the class should have the default constructor

52 C++ Programming: Program Design Including Data Structures, Fourth Edition52 Arrays of Class Objects and Constructors (continued)

53 C++ Programming: Program Design Including Data Structures, Fourth Edition53 Destructors Destructors are functions without any type The name of a destructor is the character ' ~ ' followed by class name −For example: ~clockType(); A class can have only one destructor −The destructor has no parameters The destructor is automatically executed when the class object goes out of scope

54 C++ Programming: Program Design Including Data Structures, Fourth Edition54 Data Abstract, Classes, and Abstract Data Types Abstraction −Separating design details from usage −Separating the logical properties from the implementation details Abstraction can also be applied to data −Abstract data type (ADT): data type that separates the logical properties from the implementation details

55 C++ Programming: Program Design Including Data Structures, Fourth Edition55 Data Abstract, Classes, and Abstract Data Types (continued)

56 C++ Programming: Program Design Including Data Structures, Fourth Edition56 Data Abstract, Classes, and Abstract Data Types (continued)

57 C++ Programming: Program Design Including Data Structures, Fourth Edition57 Data Abstract, Classes, and Abstract Data Types (continued)

58 C++ Programming: Program Design Including Data Structures, Fourth Edition58 A struct Versus a class By default, members of a struct are public − private specifier can be used in a struct to make a member private By default, the members of a class are private class es and struct s have the same capabilities

59 C++ Programming: Program Design Including Data Structures, Fourth Edition59 A struct Versus a class (continued) In C++, the definition of a struct was expanded to include member functions, constructors, and destructors If all member variables of a class are public and there are no member functions −Use a struct

60 C++ Programming: Program Design Including Data Structures, Fourth Edition60 Information Hiding Information hiding: hiding the details of the operations on the data Interface (header) file: contains the specification details Implementation file: contains the implementation details In header file, include function prototypes and comments that briefly describe the functions −Specify preconditions and/or postconditions

61 C++ Programming: Program Design Including Data Structures, Fourth Edition61 Information Hiding (continued) Precondition: A statement specifying the condition(s) that must be true before the function is called Postcondition: A statement specifying what is true after the function call is completed

62

63

64

65 C++ Programming: Program Design Including Data Structures, Fourth Edition65 Information Hiding (continued) Header file has an extension.h Implementation file has an extension.cpp Implementation file must include header file via include statement In include statement: −User-defined header files are enclosed in double quotes −System-provided header files are enclosed between angular brackets

66 C++ Programming: Program Design Including Data Structures, Fourth Edition66 Executable Code To use an object in a program −The program must be able to access the implementation Visual C++, Visual Studio.NET, C++ Builder, and CodeWarrior put the editor, compiler, and linker into a package −With one command, the program is compiled and linked with the other necessary files −These systems also manage multiple file programs in the form of a project

67 C++ Programming: Program Design Including Data Structures, Fourth Edition67 Executable Code (continued) A project consists of several files, called the project files These systems usually have a command, called build, rebuild, or make When applied to a project, system compiles and links all files required to create the executable code −When file(s) in the project change, use these commands to recompile and relink the files

68

69 C++ Programming: Program Design Including Data Structures, Fourth Edition69 Executable Code (continued)

70

71 C++ Programming: Program Design Including Data Structures, Fourth Edition71 Static Members of a Class Use the keyword static to declare a function or variable of a class as static A public static function or member of a class can be accessed using the class name and the scope resolution operator static member variables of a class exist even if no object of that class type exists

72 C++ Programming: Program Design Including Data Structures, Fourth Edition72 Programming Example: Candy Machine A common place to buy candy is a candy machine This candy machine currently sells candies, chips, gum, and cookies A new candy machine is bought for the gym, but it is not working properly You have been asked to write a program so it can be put into operation

73 C++ Programming: Program Design Including Data Structures, Fourth Edition73 Programming Example: Candy Machine (continued) The program should: −Show the customer the different products sold −Let the customer make the selection −Show the customer the cost of the item −Accept money from the customer −Release the item Input: item selection and cost of the item Output: selected item

74 C++ Programming: Program Design Including Data Structures, Fourth Edition74 Programming Example: Problem Analysis A candy machine has two main components: −A built-in cash register −Several dispensers to hold and release the product

75

76 C++ Programming: Program Design Including Data Structures, Fourth Edition76 Programming Example: Problem Analysis (continued)

77

78 C++ Programming: Program Design Including Data Structures, Fourth Edition78 Programming Example: Problem Analysis (continued)

79

80 C++ Programming: Program Design Including Data Structures, Fourth Edition80 Programming Example: Main Program When the program executes, it must: −Show the different products sold −Show how to select a particular product −Show how to terminate the program These instructions must be displayed after processing each selection Once the user has made a selection −Candy machine must act accordingly

81 C++ Programming: Program Design Including Data Structures, Fourth Edition81 Programming Example: Main Program (continued) If the user wants to a buy a product and the product is available −Candy machine should show product cost and ask the user to deposit money If the money deposited is at least the cost of the item −Candy machine should sell the item and display an appropriate message

82 C++ Programming: Program Design Including Data Structures, Fourth Edition82 Programming Example: Menu Show the selection to the customer Get selection If selection is valid and the dispenser corresponding to the selection is not empty, sell the product

83 C++ Programming: Program Design Including Data Structures, Fourth Edition83 Programming Example: Menu (continued) The menu ( showSelection ) looks like: *** Welcome to Shelly's Candy Shop ***" To select an item, enter 1 for Candy 2 for Chips 3 for Gum 4 for Cookies 9 to exit

84 C++ Programming: Program Design Including Data Structures, Fourth Edition84 Programming Example: sellProduct If the dispenser is nonempty: −Prompt customer to enter the item cost −Get the amount entered by the customer −If the amount entered by the customer is less than the cost of the product Prompt customer to enter additional amount Calculate total amount entered by the customer

85 C++ Programming: Program Design Including Data Structures, Fourth Edition85 Programming Example: sellProduct (continued) If the dispenser is nonempty: (continued) −If amount entered by the customer is at least the cost of the product Update the amount in the cash register Sell the product; that is, decrement the number of items in the dispenser by 1, display an appropriate message −If amount entered is less than cost of item Ask user to deposit additional money −If the dispenser is empty Tell the user that this product is sold out

86 C++ Programming: Program Design Including Data Structures, Fourth Edition86 Programming Example: main Declare a variable of type cashRegister Declare and initialize four objects dispenserType For example: −The statement dispenserType candy(100, 50); creates a dispenser object, candy, to hold candies; the number of items in the dispenser is 100 and the cost of an item is 50 cents

87 C++ Programming: Program Design Including Data Structures, Fourth Edition87 Programming Example: main (continued) Declare additional variables as necessary Show menu Get the selection While not done (9 exits) −Sell product ( sellProduct ) −Show selection ( showSelection ) −Get selection

88 C++ Programming: Program Design Including Data Structures, Fourth Edition88 Summary Class: collection of a fixed number of components Members: components of a class −Accessed by name −Classified into one of three categories: private, protected, and public Class variables are called class objects or, simply, objects

89 C++ Programming: Program Design Including Data Structures, Fourth Edition89 Summary (continued) The only built-in operations on classes are the assignment and member selection Constructors guarantee that data members are initialized when an object is declared −Default constructor has no parameters Destructors automatically execute when a class object goes out of scope −A class can have only one destructor −The destructor has no parameters

90 C++ Programming: Program Design Including Data Structures, Fourth Edition90 Summary (continued) Abstract data type (ADT): data type that separates the logical properties from the implementation details A public static member, function or data, of a class can be accessed using the class name and the scope resolution operator Static data members of a class exist even when no object of the class type exists Instance variables: non-static data members

91 Chapter 8 Starting Out with C++: Early Objects 5/e slide 91 © 2006 Pearson Education. All Rights Reserved 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

92 Chapter 8 Starting Out with C++: Early Objects 5/e slide 92 © 2006 Pearson Education. All Rights Reserved 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

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

94 Chapter 8 Starting Out with C++: Early Objects 5/e slide 94 © 2006 Pearson Education. All Rights Reserved 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

95 Chapter 8 Starting Out with C++: Early Objects 5/e slide 95 © 2006 Pearson Education. All Rights Reserved //This is the file “sale.h” class Sale { private: double taxRate; double total; void calcSale(double cost) {total = cost + (cost * taxRate); } public: Sale(double rate,double cost) { taxRate = rate; calcSale(cost);} Sale(double cost) { taxRate = 0; total = cost; } Sale( ) { taxRate = 0.0; total = 0.0; } double getTotal( ) { return total; } };

96 Chapter 8 Starting Out with C++: Early Objects 5/e slide 96 © 2006 Pearson Education. All Rights Reserved //Problem: Point out the output results of the program #include using namespace std; #include "sale.h" int main(){ Sale cashier1(.05, 100.0); Sale cashier2(100.0); Sale cashier3; cout << cashier1.getTotal() << endl; cout << cashier2.getTotal() << endl; cout << cashier3.getTotal() << endl; return 0; }

97 Chapter 8 Starting Out with C++: Early Objects 5/e slide 97 © 2006 Pearson Education. All Rights Reserved 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);

98 Chapter 8 Starting Out with C++: Early Objects 5/e slide 98 © 2006 Pearson Education. All Rights Reserved 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

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

100 Chapter 8 Starting Out with C++: Early Objects 5/e slide 100 © 2006 Pearson Education. All Rights Reserved 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)

101 Chapter 8 Starting Out with C++: Early Objects 5/e slide 101 © 2006 Pearson Education. All Rights Reserved 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

102 Chapter 8 Starting Out with C++: Early Objects 5/e slide 102 © 2006 Pearson Education. All Rights Reserved class Sale { private: double taxRate; double total; void calcSale(double cost) {total = cost + (cost * taxRate); } public: Sale(double rate,double cost) { taxRate = rate; calcSale(cost);} Sale(double cost) { taxRate = 0; total = cost; } Sale( ) { taxRate = 0.0; total = 0.0; } double getTotal( ) { return total; } };

103 Chapter 8 Starting Out with C++: Early Objects 5/e slide 103 © 2006 Pearson Education. All Rights Reserved //this is file sale.h class Sale { private: double taxRate; double total; void calcSale(double cost) ; public: Sale(double rate,double cost) ; Sale(double cost) ; Sale( ) ; double getTotal( ); };

104 Chapter 8 Starting Out with C++: Early Objects 5/e slide 104 © 2006 Pearson Education. All Rights Reserved //this is file sale.cpp #include "sale.h" void Sale::calcSale(double cost) {total = cost + (cost * taxRate); } Sale::Sale(double rate,double cost) { taxRate = rate; calcSale(cost);} Sale::Sale(double cost) { taxRate = 0; total = cost; } Sale::Sale( ) { taxRate = 0.0; total = 0.0; } double Sale::getTotal( ) { return total; }

105 Chapter 8 Starting Out with C++: Early Objects 5/e slide 105 © 2006 Pearson Education. All Rights Reserved //this is file main.cpp #include #include "sale.h" using namespace std; int main(){ Sale s(.005, 100); cout<<s.getTotal(); return 0; }

106 Chapter 8 Starting Out with C++: Early Objects 5/e slide 106 © 2006 Pearson Education. All Rights Reserved //this is file sale.h class Sale { private: double taxRate; double total; void calcSale(double cost) ; public: Sale(double rate,double cost) ; Sale(double cost) ; Sale( ) ; double getTotal( ); };

107 Chapter 8 Starting Out with C++: Early Objects 5/e slide 107 © 2006 Pearson Education. All Rights Reserved #include using namespace std; class BigNum{ private: int biggest; void determineBiggest(int num){ if (num > biggest) biggest = num; } public: BigNum() { biggest = 0; } bool examineNum(int) int getBiggest( ) { return biggest; } };

108 Chapter 8 Starting Out with C++: Early Objects 5/e slide 108 © 2006 Pearson Education. All Rights Reserved bool BigNum::examineNum(int n) { bool goodValue = true; if (n > 0) determineBiggest(n); else goodValue = false; return goodValue; }


Download ppt "C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction."

Similar presentations


Ads by Google