OOP Lab 9 - Reusability Ill (Function Overloading Overriding).doc

This preview shows page 1 - 5 out of 10 pages.

Lab Manual for Object-Oriented Programming(LAB-9)Function Overloading and Function OverridingDepartment of Computer Science,MAJUPage 98
Lab 9 - Function Overloading and Function OverridingTable of Contents1.Introduction1002.Activity Time Boxing1003.Objective of the Experiment1014.Concept Map1015.Homework before Lab1015.1Problem Solution Modeling1015.2Practices from home1026.Procedure & Tools1026.1Tools1026.2Setting-up Visual Studio 20171026.3Walkthrough Task1027.Practice Tasks1047.1Practice Task 11047.2Practice Task 21047.3Outcomes1057.4Testing1058.Evaluation Task (Unseen)1059.Evaluation Criteria10510.Further Reading10510.1Books10510.2Slides105Capital University of Science and Technology, IslamabadDepartment of Computer Science (2019)Page 99
Lab 9 - Function Overloading and Function OverridingLab 9: Function Overloading and Function Overriding1.IntroductionEarlier in Lab-08, you have already studied that a sub/derived class is able to access all non-private data members and member functions of the base/parent class. Moreover, besidesinheriting attributes and behaviors from base class(es), the derived class also contains its owndata members and member functions.Function overloading is the availability of various functions within a class that differ from eachother in function signature i.e. various functions share same name with different parameter typesor number of parameters. Inheritance is not necessarily required to overload functions within aprogram.On the other hand, in function overriding, there must exists inheritance relationship betweenclasses (i.e. base and derived) and functions’ signature are also required to be same in both parentand child class(es). However, derived class(es) redefine function(s) having signature similar tobase class’s function(s).Following code provides an example where both concepts (function overloading and overriding)have been elaborated:classBase{protected:voidmyFunc(){cout<<"Base Class’ Function";}};classDerived: public Base{public:void myFunc(){cout<<"Derived Class’ Function";}void myFunc(inta){cout<<"Derived Class’ Function with Parameter Value" <<a;}};In the given example (above),Capital University of Science and Technology, IslamabadDepartment of Computer Science (2019)Page 100
Lab 9 - Function Overloading and Function OverridingAt first, the classDerivedshows function overloading while containing two functionsdiffer from each other in function signature (i.e. functionsmyFunc()andmyFunc(int))Secondly, it also shows function overriding as it holds two function implementations withsame signature (i.e. besidesmyFunc()of its own, it also containsmyFunc()inherited fromthe Base class.Relevant Lecture Readings:Textbook:Object-Oriented Programming Using C++, Fourth edition, Robert Lafore.oPages:188-193, 382-3922.Activity Time BoxingTable 1: Activity Time BoxingTaskNo.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 10 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
NoProfessor
Tags
Object Oriented Programming, Department of Computer Science

Newly Uploaded Documents

Show More

Newly Uploaded Documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture