🗊 Презентация C++ Classes How to Create and Use Them (Constructor, Destructor)

Нажмите для полного просмотра!
C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №1 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №2 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №3 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №4 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №5 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №6 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №7 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №8 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №9 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №10 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №11 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №12 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №13 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №14 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №15 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №16 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №17 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №18 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №19 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №20 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №21 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №22 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №23 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №24 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №25 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №26 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №27 C++ Classes How to Create and Use Them (Constructor, Destructor), слайд №28

Вы можете ознакомиться и скачать презентацию на тему C++ Classes How to Create and Use Them (Constructor, Destructor). Доклад-сообщение содержит 28 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1


C++ Classes How to Create and Use Them (Constructor, Destructor) By Kouros
Описание слайда:
C++ Classes How to Create and Use Them (Constructor, Destructor) By Kouros

Слайд 2


Overview Functions in Classes (methods) Constructor Accessors/Modifiers Miscellaneous Terminology File Topology Designing Classes The Driver and...
Описание слайда:
Overview Functions in Classes (methods) Constructor Accessors/Modifiers Miscellaneous Terminology File Topology Designing Classes The Driver and Object instantiation

Слайд 3


Class Constructors A class constructor is a member function whose purpose is to initialize the private data members of a class object The name of a...
Описание слайда:
Class Constructors A class constructor is a member function whose purpose is to initialize the private data members of a class object The name of a constructor is always the name of the class, and there is no return type for the constructor A class may have several constructors with different parameter lists. A constructor with no parameters is the default constructor A constructor is implicitly and automaticly invoked when a class object is declared--if there are parameters, their values are listed in parentheses in the declaration

Слайд 4


Specification of TimeType Class Constructors class TimeType // timetype.h { public : // 7 function members void Set ( int hours , int minutes , int...
Описание слайда:
Specification of TimeType Class Constructors class TimeType // timetype.h { public : // 7 function members void Set ( int hours , int minutes , int seconds ) ; void Increment ( ) ; void Write ( ) const ; bool Equal ( TimeType otherTime ) const ; bool LessThan ( TimeType otherTime ) const ; TimeType ( int initHrs , int initMins , int initSecs ) ; // constructor TimeType ( ) ; // default constructor private : // 3 data members int hrs ; int mins ; int secs ; } ;

Слайд 5


Implementation of TimeType Default Constructor TimeType :: TimeType ( ) // Default Constructor // Postcondition: // hrs == 0 && mins == 0 && secs ==...
Описание слайда:
Implementation of TimeType Default Constructor TimeType :: TimeType ( ) // Default Constructor // Postcondition: // hrs == 0 && mins == 0 && secs == 0 { hrs = 0 ; mins = 0 ; secs = 0 ; }

Слайд 6


Implementation of Another TimeType Class Constructor TimeType :: TimeType (int initHrs, int initMins, int initSecs ) // Constructor // Precondition: 0
Описание слайда:
Implementation of Another TimeType Class Constructor TimeType :: TimeType (int initHrs, int initMins, int initSecs ) // Constructor // Precondition: 0

Слайд 7


Automatic invocation of constructors occurs Main(){ TimeType departureTime ; // default constructor invoked TimeType movieTime (19, 30, 0 ) ; //...
Описание слайда:
Automatic invocation of constructors occurs Main(){ TimeType departureTime ; // default constructor invoked TimeType movieTime (19, 30, 0 ) ; // parameterized constructor departureTime movieTime }

Слайд 8


The Class Destructor A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or...
Описание слайда:
The Class Destructor A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class. A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.

Слайд 9


Destructor example CDog ::~CDog (void) { cout
Описание слайда:
Destructor example CDog ::~CDog (void) { cout

Слайд 10


A “real life” example The CDog Attributes (characteristics) rabid or not rabid (bool) weight (int or float) name (char [ ]) Behaviors growl eat
Описание слайда:
A “real life” example The CDog Attributes (characteristics) rabid or not rabid (bool) weight (int or float) name (char [ ]) Behaviors growl eat

Слайд 11


Step 1: The Skeleton class CDog { // attributes will go here – name, weight, rabid // behaviors will go here – growl, eat };
Описание слайда:
Step 1: The Skeleton class CDog { // attributes will go here – name, weight, rabid // behaviors will go here – growl, eat };

Слайд 12


Step 2: The attributes class CDog { public: boolean rabid; int weight; char name[255]; // Behaviors go here };
Описание слайда:
Step 2: The attributes class CDog { public: boolean rabid; int weight; char name[255]; // Behaviors go here };

Слайд 13


Step 3: The Constructor This is a special function Used to give initial values to ALL attributes Is activated when someone creates a new instance of...
Описание слайда:
Step 3: The Constructor This is a special function Used to give initial values to ALL attributes Is activated when someone creates a new instance of the class The name of this function MUST be the same name as the class

Слайд 14


Step 3: Designing the Constructor Constructors will vary, depending on design Ask questions: Are all CDogs born either rabid or non-rabid? (yes –...
Описание слайда:
Step 3: Designing the Constructor Constructors will vary, depending on design Ask questions: Are all CDogs born either rabid or non-rabid? (yes – they are all born non-rabid) Are all CDogs born with the same weight? (no – they are born with different weights) Are all CDogs born with the same name? (no – they all have different names) If ever “no”, then you need information passed in as parameters.

Слайд 15


Step 3: The Constructor class CDog { public: boolean rabidOrNot; int weight; char name [255]; // Constructor CDog::CDog (int x, String y) { rabid =...
Описание слайда:
Step 3: The Constructor class CDog { public: boolean rabidOrNot; int weight; char name [255]; // Constructor CDog::CDog (int x, String y) { rabid = false; weight = x; strcpy (name, y); } // Behaviors go here };

Слайд 16


Back to CDog class CDog { public: boolean rabidOrNot; int weight; char name [255]; // Constructor CDog::CDog (int x, char y[ ]) { rabid = false;...
Описание слайда:
Back to CDog class CDog { public: boolean rabidOrNot; int weight; char name [255]; // Constructor CDog::CDog (int x, char y[ ]) { rabid = false; weight = x; strcpy (name, y); } CDog ::~CDog () { cout

Слайд 17


Miscellaneous Methods Follow the pattern void CDog::eat ( ) { cout
Описание слайда:
Miscellaneous Methods Follow the pattern void CDog::eat ( ) { cout

Слайд 18


Add Methods class CDog { public: boolean rabidOrNot; int weight; char name [255]; // Constructor CDog::CDog (int x, char y[ ]) { rabid = false;...
Описание слайда:
Add Methods class CDog { public: boolean rabidOrNot; int weight; char name [255]; // Constructor CDog::CDog (int x, char y[ ]) { rabid = false; weight = x; strcpy (name, y); } void CDog::eat ( ) { cout

Слайд 19


Create New Object(Instance) Cdog c1 ; // create an object that run default constructor CDog c2 (7, “Ethel”); // create an object that run other...
Описание слайда:
Create New Object(Instance) Cdog c1 ; // create an object that run default constructor CDog c2 (7, “Ethel”); // create an object that run other constructor CDog* c1 = new CDog (14, “Bob”); // create a pointer object

Слайд 20


The “.” and “->” operators “Dot” operator used for non-pointers to: Get to an instances attributes Get to an instances methods Basically get inside...
Описание слайда:
The “.” and “->” operators “Dot” operator used for non-pointers to: Get to an instances attributes Get to an instances methods Basically get inside the instance Format: . Arrow operator used for pointers Format: ->

Слайд 21


Using the “.” and “->” Operators #include void main ( ) { CDog* c1; c1 = new CDog (14, “Bob”); CDog c2 (7, “Ethel”); c2.bark( ); c1->growl( ); }
Описание слайда:
Using the “.” and “->” Operators #include void main ( ) { CDog* c1; c1 = new CDog (14, “Bob”); CDog c2 (7, “Ethel”); c2.bark( ); c1->growl( ); }

Слайд 22


Accessors and Modifiers Accessor for the rabid attribute bool CDog::getRabid ( ) { return rabid; } Modifier for the rabid attribute void...
Описание слайда:
Accessors and Modifiers Accessor for the rabid attribute bool CDog::getRabid ( ) { return rabid; } Modifier for the rabid attribute void CDog::setRabid (bool myBoolean) { rabid = myBoolean; } Put these inside of the CDog class

Слайд 23


Using accessors and modifiers #include void main ( ) { CDog* c1; c1 = new CDog (14, “Bob”); CDog c2 (7, “Ethel”); c1->setRabid (1); // prints 1 for...
Описание слайда:
Using accessors and modifiers #include void main ( ) { CDog* c1; c1 = new CDog (14, “Bob”); CDog c2 (7, “Ethel”); c1->setRabid (1); // prints 1 for true cout getRabid( )

Слайд 24


Make a Separate Header File (for the generic description) class CDog { public: int weight; bool rabid; char name [ ]; CDog (int x, char y[ ]); bool...
Описание слайда:
Make a Separate Header File (for the generic description) class CDog { public: int weight; bool rabid; char name [ ]; CDog (int x, char y[ ]); bool getRabid ( ); void setRabid (bool x); char [ ] getName ( ); void setName (char z[ ]); int getWeight ( ); void setWeight (int x); void bark( ); void growl( ); };

Слайд 25


Our Final CDog.cpp #include #include // Constructor CDog::CDog (int x, char y[ ]) { rabid = false; weight = x; strcpy(name, y); } void CDog::eat ( )...
Описание слайда:
Our Final CDog.cpp #include #include // Constructor CDog::CDog (int x, char y[ ]) { rabid = false; weight = x; strcpy(name, y); } void CDog::eat ( ) { cout

Слайд 26


Hierarchical (Nested) class class Host { public: class Nested { public: void PrintMe() { cout
Описание слайда:
Hierarchical (Nested) class class Host { public: class Nested { public: void PrintMe() { cout

Слайд 27


Simple Nested class class A{...}; class B{ public: A a;//declare members B() : a(...) { } // constructors are called here };
Описание слайда:
Simple Nested class class A{...}; class B{ public: A a;//declare members B() : a(...) { } // constructors are called here };

Слайд 28


Summary of Class Concepts A class is a generic description which may have many instances When creating classes Make the constructor Make the...
Описание слайда:
Summary of Class Concepts A class is a generic description which may have many instances When creating classes Make the constructor Make the accessors/modifiers/miscellaneous Classes go in separate files The “.” and “->” operators tell the instances which method to run



Похожие презентации
Mypresentation.ru
Загрузить презентацию