Data Hiding, Public Interface - Introduction to Programming - Lecture Slides, Slides of Computer Programming

Data Hiding, Public Interface, Member of the class, class Date, class Person, Public member functions, Member object, Initializer List, Inside Constructor for object Row are the key points of this lecture.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

somo
somo 🇮🇳

4.8

(4)

70 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to Programming
Lecture 40
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Data Hiding, Public Interface - Introduction to Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Introduction to Programming

Lecture 40

Class Class is a user defined data type.

Public Interface

Yes you can use user defined data type as a member of the class Class can contain objects.

Example

class Person

private :

char * name ;

char * address ;

Date dateOfBirth ; // member object

public :

// public member functions...

Person :: Person ( char * name , char * address , int day , int month , int year )
dateOfBirth.setDay ( dy ) ;
dateOfBirth.setMonth ( mn ) ;
dateOfBirth.setYear ( yr ) ;
// statement ( s ) ;

Person :: Person ( char * name , char * address , int day, int month, int year ) : Date ( int month , int day , int year )

Constructor Date :: Date ( int day , int month , int year ) { cout << “Inside Date constructor ” ; } Person :: Person ( char * name , char * address ,int day , int month , int year ) : Date ( month , day , year ) { cout << “Inside Person constructor” ; }

Example class Column { private : int size ; public : Column ( ) { cout << "Column Created" << endl ; } void display ( ) ; void set ( int ) ; ~ Column ( ) { cout << "Column destroyed" << endl ; } } ; Docsity.com

Example class Row { private : int size ; Column col ; public : void set ( int ) ; Row ( ) { cout << "Inside Constructor for object Row" << endl ; } ~ Row ( ) { cout << "Row destroyed" << endl ; } void display ( ) ; } ; Docsity.com

main( ) { Matrix m ; m.display ( ) ; } Example

Column Created Inside Constructor for object Row Matrix Created …. Matrix Destroyed Row Destroyed Column Destroyed Output

const Date dateOfBirth ;

Structure inside a structure