#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class media
{
protected:
char title[20];
double price;
public:
media(char *s,double p)
{
strcpy(title,s);
price=p;
}
virtual void display()=0;
};
class book:public media
{
int noofpages;
public:
book(char *s,double a,int p):media(s,a)
{
noofpages=p;
}
void display()
{
cout<<"\n Title :"<<title;
cout<<"\n Pages :"<<noofpages;
cout<<"\n prices :"<<price;
}
};
class tape:public media
{
int playtime;
public:
tape(char *s,double a,int pt):media(s,a)
{
playtime=pt;
}
void display()
{
cout<<"\n Title : "<<title;
cout<<"\n playtime:"<<playtime<<"minutes";
cout<<"\n price :"<<price;
}
};
void main()
{
clrscr();
char t[100];
double pr;
int pt,nop;
media *m;
cout<<"Enter the title,no of pages & price of a book :\n";
gets(t);
cin>>nop>>pr;
book b(t,pr,nop);
cout<<"Enter the title,price and playtime(in min) of a tape :\n";
gets(t);
cin>>pr>>pt;
tape T(t,pr,pt);
m=&b;
clrscr();
cout<<"\n Book information ";
m->display();
m=&T;
cout<<"\n \n Tape information ";
m->display();
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
class media
{
protected:
char title[20];
double price;
public:
media(char *s,double p)
{
strcpy(title,s);
price=p;
}
virtual void display()=0;
};
class book:public media
{
int noofpages;
public:
book(char *s,double a,int p):media(s,a)
{
noofpages=p;
}
void display()
{
cout<<"\n Title :"<<title;
cout<<"\n Pages :"<<noofpages;
cout<<"\n prices :"<<price;
}
};
class tape:public media
{
int playtime;
public:
tape(char *s,double a,int pt):media(s,a)
{
playtime=pt;
}
void display()
{
cout<<"\n Title : "<<title;
cout<<"\n playtime:"<<playtime<<"minutes";
cout<<"\n price :"<<price;
}
};
void main()
{
clrscr();
char t[100];
double pr;
int pt,nop;
media *m;
cout<<"Enter the title,no of pages & price of a book :\n";
gets(t);
cin>>nop>>pr;
book b(t,pr,nop);
cout<<"Enter the title,price and playtime(in min) of a tape :\n";
gets(t);
cin>>pr>>pt;
tape T(t,pr,pt);
m=&b;
clrscr();
cout<<"\n Book information ";
m->display();
m=&T;
cout<<"\n \n Tape information ";
m->display();
getch();
}
No comments:
Post a Comment