0% found this document useful (0 votes)
12 views3 pages

Practical No.03 OOP

SE practicals

Uploaded by

ayushikhar16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Practical No.03 OOP

SE practicals

Uploaded by

ayushikhar16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Rutuja Kharade

Roll No: S212005


Class: SE
Div: B
Batch: B1
Sub: OOP

PRACTICAL NO. 3
(GROUP A)

Problem Statement: Imagine a publishing company which does marketing for


book and audio cassette versions. Create a class publication that stores the title (a
string) and price (type float) of a publication. From this class derive two classes:
book, which adds a page count (type int), and tape, which adds a playing time in
minutes (type float). Write a program that instantiates the book and tape classes,
allows user to enter data and displays the data members. If an exception is caught,
replace all the data member values with zero values.

CODE
#include<iostream>
using namespace std;
class publication
{
public:
string title;
float price;
};
class book:public publication
{
public:
int pagecount;
void info()
{
cout<<"\nDetails of book publication"<<endl;
cout<<"Enter the title: "<<endl;
getline(cin,title);
cout<<"Enter the price: "<<endl;
cin>>price;
cout<<"Enter page count: "<<endl;
cin>>pagecount;
if(title==" " || price<=0 || pagecount<=0)
{
title="Empty";
price=0.0;
pagecount=0;
}
}
void display()
{
cout<<"\nDetails of Book publication"<<endl;
cout<<"The title of the book publication is: "<<title<<endl;
cout<<"The price of the book publication is: "<<price<<endl;
cout<<"The page count of the book is: "<<pagecount<<endl;
}
};
class tape:public publication
{
public:
float play_time;
void details()
{
cout<<"\nDetails of audio tape publication"<<endl;
cout<<"Enter the title: "<<endl;
cin>>title;
cout<<"Enter the price: "<<endl;
cin>>price;
cout<<"Enter audio play time in minutes: "<<endl;
cin>>play_time;
if(title==" " || price<=0 || play_time<=0)
{
title="Empty";
price=0.0;
play_time=0;
}
}
void display()
{
cout<<"\nDetails of audio tape "<<endl;
cout<<"The title of the audio tape publication is: "<<title<<endl;
cout<<"The price of audio tape is: "<<price<<endl;
cout<<"The audio play time is: "<<play_time<<" minutes"<<endl;
}
};
int main()
{
book b;
tape t;
b.info();
t.details();
b.display();
t.display();
return 0;
}

INPUT / OUTPUT

You might also like