0% found this document useful (0 votes)
5 views4 pages

Oops 4

The document describes an assignment to create a publishing company simulation using C++. It involves a base class 'Publication' with derived classes 'Book' and 'Tape', which include additional attributes for page count and playing time respectively. The program allows user input for these attributes and handles exceptions by resetting values to zero in case of invalid input.

Uploaded by

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

Oops 4

The document describes an assignment to create a publishing company simulation using C++. It involves a base class 'Publication' with derived classes 'Book' and 'Tape', which include additional attributes for page count and playing time respectively. The program allows user input for these attributes and handles exceptions by resetting values to zero in case of invalid input.

Uploaded by

prajwalcharthad6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NAME : Prajwal Prashant Charthad

ROLL NO: 133


Assignment no :4
Title: 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.

Program:

#include
<iostream>
#include <string>
#include<stdexce
pt>
usingnamespacestd;

classPublication{ protecte
d:
stringtitle
;
floatprice
;
public:
Publication():title(""),price(0.
0){} virtual void getData() {
try{
cout<<"Entertitle:
"; [Link]();
getline(cin, title);
cout<<"Enterprice:
"; cin >> price;
if([Link]())throwruntime_error("Invalidpriceinput");
} catch (...)
{ title = "";
price=0.0;
[Link]();
[Link](10000,'\n');
cout<<"Error:[Link]."<<endl;
}
}
virtual void displayData()
const {cout <<"Title: "<<
title << endl; cout<<"Price:
$"<<price<<en
};
classBook:publicPublication{ pri
vate:
intpageCount;
public:
Book() : pageCount(0)
{}
voidgetData()override{
Publication::getData();
try{
cout<<"Enterpagecount:"
; cin >> pageCount;
if([Link]())throwruntime_error("Invalidpagecountinput");
} catch (...)
{ title = "";
price=0.0;
pageCount=0;
[Link]();

[Link](10000,'\n');
cout<<"Error:[Link]."<<endl;
}
}
voiddisplayData()constoverri
de{ Publication::displayData(
);
cout<<"PageCount:"<<pageCount<<endl;
}
};
classTape:publicPublication{ pri
vate:
floatplayingTim
e; public:
Tape():playingTime(0
.0){} void getData()
override {
Publication::getData
(); try {
cout<<"Enterplayingtimeinminutes:
"; cin >> playingTime;
if([Link]())throwruntime_error("Invalidplayingtimeinput");
} catch (...)
{ title = "";
price=0.0;
playingTime = 0.0;
[Link]();
[Link](10000,'\
n');
cout<<"Error:[Link]."<<endl;
}
}
voiddisplayData()constoverri
de{ Publication::displayData(
);
cout<<"PlayingTime(minutes):"<<playingTime<< endl;
}
};
int main()
{
Bookboo
k; Tape
tape;
cout<<"EnterdataforBook:"<<endl;
[Link](); cout<<"\
nDisplayingBookdata:"<<endl;
[Link](); cout<<"\
nEnterdataforTape:"<<endl; [Link]();
cout<<"\nDisplayingTapedata:"<<endl;
[Link]();
return0;
}

OUTPUT:

You might also like