Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC241: Object Oriented Programming

Similar presentations


Presentation on theme: "CSC241: Object Oriented Programming"— Presentation transcript:

1 CSC241: Object Oriented Programming
Lecture No 24

2 Previous Lecture Efficient string class Dynamic Type Information
Resolve problem while deleting String objects Dynamic Type Information dynamic_cast operator Checking class type pDerv1 = dynamic_cast<Derv1*>(pUnknown) Changing Pointer Types typeid operator Class name of object

3 Today’s Lecture Example programs Intro to Generic Programming
Publication company Distance class Intro to Generic Programming template

4 Example program 1 Imagine the publishing company that markets both book and audiocassette versions of its works create a class publication (private data: title, price) derive two classes: book, which adds a page count (type int) tape, which adds a playing time in minutes (type float) Each of the three classes should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display the data Write a main() program that creates an array of pointers to publication

5 Cont. In a loop, ask the user for data about a book or tape, and use new to create an object of type book or tape When the user has finished entering the data display the resulting data using a for loop and a single statement such as pubarr[j]->putdata(); Write a program

6 Example program 2 In the Distance class, create an overloaded * operator so that two distances can be multiplied together. Make it a friend function so that you can use such expressions as dist1 = 7.5 * dist2; Write a main() program to test this operator. Write a program

7


Download ppt "CSC241: Object Oriented Programming"

Similar presentations


Ads by Google