Write a program with use of inheritance: Define a class publisher that stores the name of the title. Derive two classes book and tape, which inherit publisher. Book class contains member data called page no and tape class contain time for playing. Define functions in the appropriate classes to get and print the details.
CODING:
#include<iostream.h>
#include<conio.h>
class publisher
{
char name[20];
public:
void set()
{
cout<<"BOOK Name:";cin>>name;
}
void out()
{
cout<<"BOOK Name:"<<name;
}
};
class book:public publisher
{
int page;
public:
void get()
{
cout<<"BOOK PAGE No:";cin>>page;
}
void disp()
{
cout<<"\nBOOK PAGE No:"<<page;
}
};
class tape:public publisher
{
int time;
public:
void get()
{
cout<<"BOOK Time:";cin>>time;
}
void disp()
{
cout<<"Playing Time:"<<time;
}
};
void main()
{
char ch;
clrscr();
do
{
cout<<"B->BOOK\nT->TAPE\nChoice:";
cin>>ch;
if(ch=='b' || ch=='B')
{
book b1;
b1.set();
b1.get();
b1.out();
b1.disp();
}
if(ch=='t' || ch=='T')
{
tape t1;
t1.get();
t1.disp();
}
cout<<"\nY->Continue\nX->Exit\nChoice:";
cin>>ch;
}while(ch!='x'|| ch=='X');
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class publisher
{
char name[20];
public:
void set()
{
cout<<"BOOK Name:";cin>>name;
}
void out()
{
cout<<"BOOK Name:"<<name;
}
};
class book:public publisher
{
int page;
public:
void get()
{
cout<<"BOOK PAGE No:";cin>>page;
}
void disp()
{
cout<<"\nBOOK PAGE No:"<<page;
}
};
class tape:public publisher
{
int time;
public:
void get()
{
cout<<"BOOK Time:";cin>>time;
}
void disp()
{
cout<<"Playing Time:"<<time;
}
};
void main()
{
char ch;
clrscr();
do
{
cout<<"B->BOOK\nT->TAPE\nChoice:";
cin>>ch;
if(ch=='b' || ch=='B')
{
book b1;
b1.set();
b1.get();
b1.out();
b1.disp();
}
if(ch=='t' || ch=='T')
{
tape t1;
t1.get();
t1.disp();
}
cout<<"\nY->Continue\nX->Exit\nChoice:";
cin>>ch;
}while(ch!='x'|| ch=='X');
getch();
}
Comments
Post a Comment