Description
A publishing house can publish books and tapes. The books are priced by the price per page multiplied by the number of pages, and the tape is priced according to the price per 10-minute times the minutes of tape recordings. Please define the Publicatioin, book, Tape, and bookstore four classes. which
1. Publication class:
1 The data member double price indicates the unit price (for books, the prices per page; for tapes, the price of recordings per 10 minutes).
2 data member int length indicates the length of the publication, the number of pages for the book, and the Minutes for the tape.
3 member function Gettotalprice () is used to return the pricing of a publication.
4 constructor Publication (double, int) is used to construct a publication.
5 member function double GetPrice () const and int getlength () are used to return the unit price and length of the publication.
6 destructor function.
2. The book class is a subclass of publication.
1 constructor Book (Double,int).
2 rewrite the Gettotalprice return pricing for the parent class, priced to the unit price multiplied by the length (that is, the number of pages).
3 destructor function.
3. Tape is a subclass of publication:
1 constructor tape (double,int).
2 rewrite the Gettotalprice return pricing for the parent class. Note: The price property is the unit cost of recording every 10 minutes, and the length of the tape is not necessarily an integral multiple of 10. Calculate the price, less than 10 minutes, according to 10 minutes calculation.
3 destructor function.
4.BookStore is a bookstore, with data member publications **pubs, is a bookstore owned list of publications; int NUM indicates the number of publications owned by the bookstore. The member function int getnumofbook () and int getnumoftape () calculates the number of books and tape that are owned in the bookstore. The class is already given in Appcode code.
Input
The input is divided into multiple lines.
The first line is an integer m>0, representing an M test case.
Each test is divided into three sections: the first part is the publication type (b indicates book,t tape), unit price, and quantity (pages or minutes).
Output
See examples.
Sample Input 3B 0.10 201T 0.50 100T 0.40- sample Output call publication ' s constructor! Call book ' s constructor! Call publication ' s constructor! Call Tape ' s constructor! Call publication ' s constructor! Call Tape ' s constructor! Call publication ' s constructor! Call book ' s constructor! Call publication ' s constructor! Call Tape ' s constructor! Call publication ' s constructor! Call Tape ' s constructor! There are 1 books and 2 tapes. Their total price are 29.50.Call book ' s de-constructor! Call publication ' s de-constructor! Call Tape ' s de-constructor! Call publication ' s de-constructor! Call Tape ' s de-constructor! Call publication ' s de-constructor! Call book ' s de-constructor! Call publication ' s de-constructor! Call Tape ' s de-constructor! Call publication ' s de-constructor! Call Tape ' s de-constructor! Call publication ' s de-constructor! Call Bookstore ' s de-constructor! HINT
Use typeID to determine the type of actual object to which the object pointer points.
#include <bits/stdc++.h> using namespace std;
Class publication{protected:double price;int length; Public:publication (double a,int b):p Rice (a), length (b) {cout<< "call publication ' s constructor!"
<<endl;
Virtual Double Gettotalprice () {} double GetPrice () {return price;}
int GetLength () {return length;} Virtual ~publication () {cout<< "call publication ' s de-constructor!"
<<endl;
}
}; Class Book:public publication{Public:book (double a,int b):P ublication (a,b) {cout<< ' call book ' C onstructor! "
<<endl;
Double Gettotalprice () {return length*price; } ~book () {cout<< "call book ' de-constructor!"
<<endl;
}
}; Class Tape:public publication{Public:tape (double a,int b):P ublication (a,b) {cout<< ' call Tape ' s C onstructor! "
<<endl; Double Gettotalprice () {double count=0;
if (length%10!=0) count+=1+ (LENGTH/10);
else COUNT=LENGTH/10;
return count*1.0*price; } ~tape () {cout<< "call Tape ' s de-constructor!"
<<endl;
}
};
Class Bookstore {private:publication **pubs;
int num;
Public:bookstore (publication **p, int n) {pubs = new publication*[n];
num = n; for (int i = 0; i < n; i++) {if (typeid (* (p[i))) = = typeID (book)) {PU
Bs[i] = new book (P[i]->getprice (), p[i]->getlength ());
else {Pubs[i] = new Tape (P[i]->getprice (), p[i]->getlength ());
Getnumofbook () {int c = 0;
for (int i = 0; i < num i++) {if (typeid (* (pubs[i))) = = typeID (book)) C + +;
return C;
int Getnumoftape () {int c = 0; for (int i = 0; i < num i++) {if (typeid (* (pubs[i))) = = typeID (Tape)) C + +;
return C;
~bookstore () {for (int i = 0; i < num; i++) {delete pubs[i];
} delete[] pubs;
cout<< "Call bookstore ' s de-constructor!\n";
}
};
int main () {int cases, date;
char type;
Double Total,price;
Publication **pub;
cin>>cases;
Pub = new Publication*[cases];
for (int i = 0; i < cases i++) {cin>>type>>price>>date;
Switch (type) {case ' B ': pub[i] = new book (price,date);
Break
Case ' T ': pub[i] = new Tape (price,date);
Break
} Bookstore Bookstore (pub, cases); cout<< "There are" <<bookstore.getnumofbook () << "Books and" <<bookstore.getnumoftape () <
< "tapes."
Total = 0; for (int i = 0; i < cases i++) {total + = Pub[i]-> gettotalprice (); } cout<< "Their Total Price" <<setprecision (2) <<fixed<<total<< "."
<<endl;
for (int i = 0; i < cases i++) {delete Pub[i];
} delete[] Pub;
return 0; }