C++ Interlude 1 C++ Classes

Slides:



Advertisements
Similar presentations
Engineering Problem Solving With C++ An Object Based Approach Additional Topics Chapter 10 Programming with Classes.
Advertisements

Operator overloading redefine the operations of operators
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
C++ Programming Languages
Approfondimento Classi - Esempi1 // Argomento: Oggetti membri di altre classi // Declaration of the Date class. // Member functions defined in date1.cpp.
Most-to-Least Legible Color Combinations for Viewing on Slide Shows Color and contrast are very important tools in communication. They can be used to enhance.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Lecture 18: 4/11/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
© red ©
Constructors 11/10/10. Today  Use constructors to initialize objects.  Use const to protect data members.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Linked Lists. Preliminaries Options for implementing an ADT List Array Has a fixed size Data must be shifted during insertions and deletions Dynamic array.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation.
Templates CS-341 Dick Steflik. Reuse Templates allow us to get more mileage out of the classes we create by allowing the user to supply certain attributes.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
CSE 250: Data Structures Week 3 January 28 – February 1, 2008.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
UML Basics & Access Modifier
Templates CS212 & CS-240. Reuse Templates allow extending our classes Allows the user to supply certain attributes at compile time. Attributes specified.
Miscellaneous JPC and JWD © 2002 McGraw-Hill, Inc.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Midterm Review CS1220 Spring Disclaimer The following questions are representative of those that will appear on the midterm exam. They do not represent.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
The Class Construct Defining objects with attributes and behavior JPC and JWD © 2002 McGraw-Hill, Inc.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
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.
Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.
GRAPHING RELATIONSHIPS For each graph, determine the graphing relationship and record it on a white board.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
My Penguin Math Book By:. I see How many penguins do you see? Count them and type the number in the box penguins.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
1 Data Structures and Algorithms Linked List. 2 Lists Lists The Linked List ADT Linked List The Linked List Class Definition Linked List Class implementation.
Regarding assignment 1 Style standards Program organization
Pointer to an Object Can define a pointer to an object:
A CLASS CONSISTS OF VARIABLES,
Classes C++ representation of an object
CS505 Data Structures and Algorithms
© 2017 Pearson Education, Hoboken, NJ. All rights reserved
CS2006- Data Structures I Chapter 5 Linked Lists I.
CS100A, Lecture 7, 22 Sept Static fields and methods
A First C++ Class – a Circle
Defining objects with attributes and behavior
C++ Object-Oriented Programming
CS250 Introduction to Computer Science II
C++ Classes C++ Interlude 1
C++ Classes C++ Interlude 1.
Colours.
Two ways to discuss color 1) Addition 2) Subtraction
Classes.
What Color is it?.
Introduction to Objects & Classes
CIS 199 Final Review.
CMSC 341 C++ and OOP.
Classes C++ representation of an object
CMSC 341 C++ and OOP.
Classes and Objects CGS3416 Spring 2019.
CMSC 341 C++ and OOP.
CS148 Introduction to Programming II
Color Box Button - Gray Type : object Type : object Type : object
Lecture 8 Object Oriented Programming (OOP)
Presentation transcript:

C++ Interlude 1 C++ Classes CS 302 Data Structures C++ Interlude 1 C++ Classes

Classes

/** @file PlainBox.h */ #ifndef _PLAIN_BOX #define _PLAIN_BOX // Set the type of data stored in the box typedef double ItemType; // Declaration for the class PlainBox class PlainBox { private: // Data field ItemType item; public: // Default constructor PlainBox (); // Parameterized constructor PlainBox (const ItemType & theItem); // Method to change the value of the data field void setItem (const ItemType & theItem); // Method to get the value of the data field ItemType getItem () const; }; // end PlainBox #endif

/. @file PlainBox. cpp. / #include "PlainBox /** @file PlainBox.cpp */ #include "PlainBox.h" PlainBox::PlainBox () { } // end default constructor PlainBox::PlainBox (const ItemType & theItem) item = theItem; } // end constructor void PlainBox::setItem (const ItemType & theItem) } // end setItem ItemType PlainBox::getItem () const const return item; } // end getItem

Templates

/** @file PlainBox.h */ #ifndef _PLAIN_BOX #define _PLAIN_BOX template < class ItemType >; // Indicates this is a template definition // Declaration for the class PlainBox class PlainBox { private: // Data field ItemType item; public: // Default constructor PlainBox (); // Parameterized constructor PlainBox (const ItemType & theItem); // Mutator method that can change the value of the data field void setItem (const ItemType & theItem); // Accessor method to get the value of the data field ItemType getItem () const; }; // end PlainBox #include "PlainBox.cpp" // Include the implementation file #endif

/** @file PlainBox.cpp */ template < class ItemType >; PlainBox < ItemType >::PlainBox () { } // end default constructor PlainBox < ItemType >::PlainBox (const ItemType & theItem) item = theItem; } // end constructor void PlainBox < ItemType >::setItem (const ItemType & theItem) } // end setItem ItemType PlainBox < ItemType >::getItem () const const return item; } // end getItem

Inheritance

/** @file ToyBox.h */ #ifndef _TOY_BOX #define _TOY_BOX #include "PlainBox.h" enum Color { BLACK, RED, BLUE, GREEN, YELLOW, WHITE }; template < class ItemType > class ToyBox:public PlainBox < ItemType > { private: Color boxColor; public: ToyBox (); ToyBox (const Color & theColor); ToyBox (const ItemType & theItem, const Color & theColor); Color getColor () const; }; // end ToyBox #include "ToyBox.cpp" #endif

/** @file ToyBox.cpp */ template < class ItemType > ToyBox < ItemType >::ToyBox () { PlainBox < ItemType > (); boxColor = BLACK; } // end default constructor ToyBox < ItemType >::ToyBox (const Color & theColor) boxColor = theColor; } // end constructor ToyBox < ItemType >::ToyBox (const ItemType & theItem, const Color & theColor) PlainBox < ItemType >::setItem (theItem); Color ToyBox < ItemType >::getColor () constconst return boxColor; } // end getColor

Abstract Classes

/** @file BoxInterface.h */ #ifndef _BOX_INTERFACE #define _BOX_INTERFACE template < class ItemType > class BoxInterface { public: virtual void setItem (const ItemType & theItem) = 0; virtual ItemType getItem () const = 0; }; // end BoxInterface #endif

End of C++ Interlude 1