Docsity

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

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