Presentation is loading. Please wait.

Presentation is loading. Please wait.

Interlude 1 C++ Classes CS 302 - Data Structures Mehmet H Gunes Modified from authors’ slides.

Similar presentations


Presentation on theme: "Interlude 1 C++ Classes CS 302 - Data Structures Mehmet H Gunes Modified from authors’ slides."— Presentation transcript:

1 Interlude 1 C++ Classes CS 302 - Data Structures Mehmet H Gunes Modified from authors’ slides

2 Contents A Problem to Solve Implementing a Solution Templates Inheritance Virtual Methods and Abstract Classes Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 http://mediaplayer.pearsoncmg.com/_ph_cc_ecs960544_set.title.Cpp_Classes __/aw/streaming/ecs_carrano_dapscpp_6/CI1_C_Classes.m4v

3 A Problem to Solve Creating a video game with a group of classes to represent three types of boxes – Plain box – Toy box – Magic box Begin by designing an ADT plain box – Use aspects of its implementation for the other two boxes View header file, Listing C1-1Listing C1-1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

4 Class Declarations Private Data Fields Constructors and Destructors Methods – Accessor methods – Mutator methods – Passing parameters by constant reference. Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

5 Class Declarations Guidelines for safe and secure programming Declare data fields as private Declare as const any method that does not change the object Declare any parameter passed by reference as const – Unless you are certain it must be modified by the method Preventing Compiler Errors Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

6 Implementing a Solution View Listing C1-2 Implementation file for the PlainBox classListing C1-2 Note a template version, Listing C1-3Listing C1-3 Implementation file for the PlainBox template class, Listing C1-4Listing C1-4 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

7 Inheritance Base Classes and Derived Classes View Listing C1-5, Template header fi le for the class ToyBoxListing C1-5 And the implementation file, Listing C1-6Listing C1-6 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

8 Overriding Base-Class Methods Redefine inherited methods Example, Listing C1-7 Header file for the class MagicBoxListing C1-7 And the implementation, Listing C1-8Listing C1-8 Consider abstract class, an interface for the ADT Box, Listing C1-9 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013


Download ppt "Interlude 1 C++ Classes CS 302 - Data Structures Mehmet H Gunes Modified from authors’ slides."

Similar presentations


Ads by Google