Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction of Programming

Similar presentations


Presentation on theme: "Introduction of Programming"— Presentation transcript:

1 Introduction of Programming
Lecture 27

2 Today’s Lecture Classes and objects Constructors Destructors
Member functions Member data

3 Function Oriented

4 Object Oriented

5 Multiple Media

6 Classes Objects Constructors

7 Data Hiding Encapsulation

8 Constructor

9 Bugs

10 The majority of programming
problems occur because of the use of un-initialized data.

11 Constructor Name of the constructor is same as the name of the class
It does not return any thing, not even void

12 Example class Date { int month ; int day ; int year ; public:
Date ( int day = 1 , int month = 1 , int year = 1 ) } ;

13 Function Overloading

14 Rules of function overloading
When ever we overload a function, the name of the function remain the same but argument list changes. The argument list can: Either vary in the number of arguments Or vary in the type

15 Example class Date { public :
Date ( int month = 1 , int day = 1 , int year = 1 ) ; private : int month , day , year ; } ;

16 Example main ( ) { Date mydate ( ) ; }

17 Example main ( ) { Date mydate ( “01-Jan-2002” ) ; }

18 Memory Allocation Inside a Constructor

19 Utility Functions

20 Friend Functions

21 Destructor

22 ~

23 Rules of Destructor Destructors cannot be overloaded
Destructors take no arguments They don’t return a value

24 Example 1 public : class Date { Date ( ) ;
Date ( int month , int day , int year ) ; ~Date ( ) ; setMonth ( int month ) ; setDay ( int day ) ; setYear ( int year ) ; int getDay ( ) ; int getMonth ( ) ; int getYear ( ) ; setDate (int day, int month, int year ) ; private: int month , day , year ; } ;

25 Example 1 main ( ) { Date mydate ( 35 , 13 , 2000 ) ; }

26 Example 1 main ( ) { Date mydate ; mydate.setDate ( 21 , 01 , 1979 ) ;
}

27 Example 1 main ( ) { Date mydate ( 21 , 01 , 1979 ) ; }

28 What Happens in Memory Functions setMonth ( int month ) ;
setDay ( int day ) ; setYear ( int year ) ; int getMonth ( ) ; int getDay ( ) ; int getYear ( ) ; int month ; int day ; int year ; int month ; int day ; int year ; int month ; int day ; int year ;

29 Example 2 main ( ) { Date date1 , date2 , date3 ;
date1.setMonth ( 3 ) ; date2.setDay ( 23 ) ; }

30 Destructors ~className ( ) ;

31 Destructors ~Date :: Date ( ) { cout<< “Object Destroyed” ; }

32 Constructors Date :: Date ( ) { cout << “Date Object Created” ;
}

33 Constructors without Arguments
Date :: Date ( ) { cout<< “Default constructor without arguments called ” ; }

34 Constructors with Arguments
Date :: Date ( int month , int day , int year ) { cout<< “A constructor with paramerters ” ; }


Download ppt "Introduction of Programming"

Similar presentations


Ads by Google