Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Object-Oriented Programming: Classes, Constructors, and Destructors, Slides of Computer Programming

An introduction to object-oriented programming concepts, focusing on classes, constructors, destructors, data hiding, and encapsulation. It covers the basics of object-oriented programming, including the use of constructors and destructors, data hiding, and function overloading. Students will learn how to define classes, create objects, and allocate memory inside constructors.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

somo
somo 🇮🇳

4.8

(4)

71 documents

1 / 34

Toggle sidebar

Related documents


Partial preview of the text

Download Object-Oriented Programming: Classes, Constructors, and Destructors and more Slides Computer Programming in PDF only on Docsity! Introduction of Programming Lecture 27 Docsity.com Today’s Lecture – Classes and objects – Constructors – Destructors – Member functions – Member data Docsity.com Multiple Media Docsity.com Classes Objects Constructors Docsity.com Data Hiding Encapsulation Docsity.com The majority of programming problems occur because of the use of un-initialized data. Docsity.com Constructor  Name of the constructor is same as the name of the class  It does not return any thing, not even void Docsity.com Example class Date { int month ; int day ; int year ; public: Date ( int day = 1 , int month = 1 , int year = 1 ) } ; Docsity.com class Date { public : Date ( int month = 1 , int day = 1 , int year = 1 ) ; private : int month , day , year ; } ; Example Docsity.com main ( ) { Date mydate ( ) ; } Example Docsity.com main ( ) { Date mydate ( “01-Jan-2002” ) ; } Example Docsity.com Friend Functions Docsity.com Destructor Docsity.com Docsity.com main ( ) { Date mydate ( 35 , 13 , 2000 ) ; } Example 1 Docsity.com main ( ) { Date mydate ; mydate.setDate ( 21 , 01 , 1979 ) ; } Example 1 Docsity.com Example 1 main ( ) { Date mydate ( 21 , 01 , 1979 ) ; } Docsity.com a Destructors ~ className ( ) ; Destructors ~Date :: Date ( ) { cout<< “Object Destroyed” ; } Docsity.com Constructors Date :: Date ( ) { cout << “Date Object Created” ; } Docsity.com