Pointer to Objects-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Pointer, Object, Static, Member, Data, Private, Array, Protected, Array, Function, Dynamic, Main, Return, Constructor, Destructor

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object Oriented Programming
(OOP)
Lecture No. 13
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 Pointer to Objects-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object Oriented Programming

(OOP)

Lecture No. 13

Review

Static data members

Static member functions

Array of objects

Example

class Student{… public:

Studen();Student(char * aName);void setRollNo(int aNo); };

Example

int main(){

Student obj;Student *ptr;ptr = &obj;ptr->setRollNo(10);return 0; }

Example

int

main(){

Student

*ptr;

ptr

new

Student;

ptr->setRollNo(10);return

Example

int

main(){

Student

*ptr;

ptr

new

Student(“Ali”);

ptr->setRollNo(10);return

Breakup of new Operation

new operator is decomposed as follows^ 

Allocating space in memory  Calling the appropriate constructor

Case Study

Design a class date through which user must be ableto perform following operations

^

Get and set current day, month and year ^

Increment by x number of days, months and year ^

Set default date

Attributes

The default date is a feature shared by allobjects^ 

This attribute must be declared a static member

Attributes in Date.h

class Date{

int day;int month;int year;static Date defaultDate; … };

Interfaces

As the default date is a static member theinterface setDefaultDate should also bedeclared static

Interfaces in Date.h

class Date{… public:

void setDay(int aDay);int getDay() const;void addDay(int x);… … };

Constructors and Destructors in

Date.h

Date(int aDay = 0,

int aMonth= 0, int aYear= 0); ~Date(); //Destructor };

Implementation of Date Class

The static member variables must beinitialized

Date Date::defaultDate (07,3,2005);