

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of various concepts in object-oriented programming (oop) using c++. Topics include creating classes, access specifiers, protected members, 'is a' relationship, and member access. Learn about the advantages, disadvantages, and real-world examples to strengthen your understanding.
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















class Date{ int day, month, year; static Date defaultDate; public: void SetDay(int aDay); int GetDay() const; void AddDay(int x); … static void SetDefaultDate( int aDay,int aMonth, int aYear); Docsity.com
Special Date
Date (^) Special Date
AddSpecialYear ...
class SpecialDate: public Date{ … public: void AddSpecialYear(int i){ ... if(day == 29 && month == 2 && !IsLeapyear(year+i)){ //ERROR! ... } } };
void SpecialDate :: AddSpecialYear
(int i){ ... if(day == 29 && month == 2 && !IsLeapyear(year+i)){ ... }
}
class Date{ … protected: bool IsLeapYear(); };
int main(){ Date aDate; aDate.IsLeapYear(); //Error return 0; }
void SpecialDate :: AddSpecialYear
(int i){ ... if(day == 29 && month == 2 && !IsLeapyear(year+i)){ ... }
}
class Person { char * name; public: ... const char * GetName(); }; class Student: public Person{ int rollNo; public: ... int GetRollNo(); };
int main(){
Person * pPtr = 0; Student s; pPtr = &s; cout << pPtr->GetName();
return 0;
}
int main(){
Person * pPtr = 0; Student s; pPtr = &s; //Error cout << pPtr->GetRollNo(); return 0;
}