C++ Classes C++ Interlude 1

Slides:



Advertisements
Similar presentations
Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Advertisements

Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
C++ data types. Structs vs. Classes C++ Classes.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
Mutable, Immutable, and Cloneable Objects Chapter 15 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 3 Array-Based Implementations CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Data Abstraction: The Walls
CSE 250: Data Structures Week 3 January 28 – February 1, 2008.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Implementations of the ADT Stack Chapter 7 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 6 Stacks CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Inheritance, Polymorphism, And Virtual Functions Chapter 15.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Class Relationships And Reuse Interlude 4 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Department of Computer Science Data Structures Using C++ 2E Chapter 2 Object-Oriented Design (OOD) and C++  Learn about inheritance  Learn about derived.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Heaps Chapter 17 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.
Inheritance Chapter 11 in Gaddis. Is a relationships in ‘real’ life Exist when one object is a specialized version of another one –Examples An english.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved More about.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 4 Link Based Implementations
Link Based Implementations
Chapter 2 Objects and Classes
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
CS 215 Final Review Ismail abumuhfouz Fall 2014.
DATA ABSTRACTION AND PROBLEM SOLVING WITH C++
Pointers, Polymorphism, and Memory Allocation
Polymorphism.
More about OOP and ADTs Classes
Chapter 16 Tree Implementations
C++ Classes C++ Interlude 1.
Exceptions C++ Interlude 3
Implementations of the ADT Stack
Chapter 4 Link Based Implementations
List Implementations Chapter 9
More about OOP and ADTs Classes
C++ Interlude 1 C++ Classes
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Objects with Functions and Arrays
Array-Based Implementations
Sorted Lists and Their Implementations
Array-Based Implementations
Fundaments of Game Design
Chapter 8: Class Relationships
CIS 199 Final Review.
Chapter 2. Problem Solving and Software Engineering
Queues and Priority Queue Implementations
ENERGY 211 / CME 211 Lecture 22 November 10, 2008.
C++ data types.
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Lecture 8 Object Oriented Programming (OOP)
Presentation transcript:

C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

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

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-1 .htm code listing files must be in the same folder as the .ppt files for these links to work Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

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

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

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

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

Overriding Base-Class Methods Redefine inherited methods Example, Listing C1-7 Header file for the class MagicBox And the implementation, Listing 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

End Chapter C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013