Você está na página 1de 2

Object Oriented Programming Paradigm (CPS-335)

LAB NO. 10
(Multiple Inheritance in C++)

Course: BESE-17A

April 26th, 2012

-----------------------------------------------------------------------------------------------------------------------------------------

Objectives:
Access Levels in inheritance. Multiple inheritance in C++.

Submission Requirements:
You are expected to complete the assigned tasks within the lab session and show them to the lab engineer/instructor. Following guidelines will be helpful to you in carrying out the tasks and preparing the lab report.

Guidelines:
Name your reports using the following convention: Lab#_Rank_YourFullName. # replaces the lab number. Rank replaces Maj/Capt/TC/NC/PC. YourFullName replaces your complete name.

You need to prepare the lab report in the pattern as explained in the lab and submit it as hard copy before next lab.

LAB TASKS
TASK I
Implement the following class hierarchy using Inheritance. A B

Object Oriented Programming Paradigm (CPS-335)

Both class A and B have a data member a of type integer and a print function to display the value of a. Class C has an additional data member b of type float. Also declare set, get methods and constructor for these three classes. Give answers to following questions: a. In which order constructors are called when object of class C is created inside main program? b. How object of class C can access data member of class A and then data member of class B? c. How object of class C can access member functions of class A and then member functions of class B?

TASK II
Consider a publishing company that markets both book and audiocassette versions of its work. Create a class publication that stores the title (a string) and price (type float) of a publication. Create a class sales that holds an array of three floats so that it can record the sales of a particular publication for the last three months. Derive two classes: book, which adds a page count (type int); and tape, which adds a playing time in minutes (type float) from both publication and sales. Each of these four classes should have a getdata () function to get its data from the user and putdata () function to display its data. An object of class book or tape should input and output publication as well as sales data along with its own data. Write a main () function to create a book object and a tape object and exercise their input/output capabilities.

TASK III
Continuing with the publication, sales, book and tape classes of Task II. Suppose you want to add the date of publication for both books and tapes. From publication class, derive a new class publication2 that includes this member data (in the form of three ints for day, month and year). Then change book and tape so that they are derived from publication2 rather than publication. Make all the necessary changes so that user can input and output dates along with all other necessary data.

Você também pode gostar