Title:-Imagine A Publishing Company Which Does Marketing For Book and Audiocassette Versions
Title:-Imagine A Publishing Company Which Does Marketing For Book and Audiocassette Versions
Title:-Imagine A Publishing Company Which Does Marketing For Book and Audiocassette Versions
Title:-Imagine a publishing company which does marketing for book and audiocassette 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.
Roll No:-
Class:-SE Computer
Date:-07/09/2020
****************************************************************************/
Note:-
Use of flush-
https://www.geeksforgeeks.org/buffer-flush-means-c/
******************************************************************************
Program-
#include<iostream>
#include<cstring>
#include<exception>
using namespace std;
class publication{
protected:
string title;
float price;
public:
publication(string t = "No title", float p = 0.0)
{
title=t;
price=p;
}
};
try
{
if(pages > 500 && pages <1500)
{
if(price >100 && price < 2000)
{
displayb();
}
}
else throw(pages);
}
catch(int i){
cout<<"Caught exception in function of book"<<endl;
cout<<"You entered an invalid data"<<endl;
title = "0";
price = 0.0;
pages = 0;
displayb();
throw;
}
}
void displayb()
{
cout<<"The book you entered is :"<<endl<<endl;
cout<<"The entered title is :"<<title<<endl;
cout<<"The entered price is :"<<price<<endl;
cout<<"The entered pages are :"<<pages<<endl;
}
};
try
{
if(min > 30.00 && min < 90.00)
{
if(price > 500 && price < 1000)
{
displayt();
}
}
else throw(min);
}
catch(float f){
cout<<"caught exception in the function of tape"<<endl;
cout<<"you entered an invalid data"<<endl;
title = "0";
price = 0.0;
min = 0.0;
displayt();
throw;
}
}
void displayt()
{
cout<<"The details of tape you entered is :"<<endl<<endl;
cout<<"The entered title is :"<<title<<endl;
cout<<"The entered price is :"<<price<<endl;
cout<<"The entered play time is :"<<min<<endl;
}
};
int main()
{
books b;
tape t;
int choice;
cout<<"Do want to buy a book(Press 1) or a tape(Press 2) :"<<flush;
cin>>choice;
switch(choice)
{
case 1: try
{
b.getb();
}
catch(int i){
cout<<"Caught exception in int main()"<<endl;
}
break;
case 2: try
{
t.gett();
}
catch(float f){
cout<<"Caught exception in int main()"<<endl;
}
break;
default:cout<<"Entered bad choice!! Try again!!"<<endl;
}
return 0;
}
/*Output:-
system@system-Lenovo:~$ g++ filename.cpp
system@system-Lenovo:~$ ./a.out
Do want to buy a book(Press 1) or a tape(Press 2) :1
Enter the details of the book :
Enter the title of the book :the man
Enter the price of the book :200
Enter the pages of the book :366
Caught exception in function of book
system@system-Lenovo:~$ ./a.out