Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- class Publication{
- protected:
- string title;
- double price;
- public:
- Publication(): title("N/A"), price(0.0) {}
- Publication(string a, double b): title(a), price(b) {}
- ~Publication() {}
- void read() {
- cout << left << setw(22) << "Enter Title: ";
- cin.sync();
- getline(cin, title);
- cin.sync();
- cout << left << setw(22) << "Enter Price: ";
- cin >> price;
- }
- void show() {
- cout << left << setw(22) << "Title: " << title << endl;
- cout << left << setw(22) << "Price: " << price << endl;
- }
- };
- class Publication2: public Publication{
- protected:
- int dd, mm, yy;
- public:
- Publication2(): dd(0), mm(0), yy(0) { Publication();}
- Publication2(string a, double b, int dd, int mm, int yy): dd(dd), mm(mm), yy(yy) { Publication(a, b);}
- ~Publication2() {}
- void read() {
- Publication::read();
- cout << left << setw(22) << "Enter Release Date: ";
- cin >> dd >> mm >> yy;
- }
- void show() {
- Publication::show();
- cout << left << setw(22) << "Realease Date: " << dd << " " << mm << " " << yy << endl;
- }
- };
- class Sale{
- protected:
- float amount[3];
- public:
- Sale(): amount({0,0,0}) {}
- Sale(float a, float b, float c): amount({a,b,c}) {}
- ~Sale() {}
- void read() {
- cout << left << setw(22) << "Enter Sales: ";
- for (int i = 0; i < 3; i++)
- cin >> amount[i];
- }
- void show() {
- cout << left << setw(22) << "Sales: ";
- for (int i = 0; i < 3; i++)
- cout << amount[i] << " ";
- cout << endl;
- }
- };
- class Book: public Publication2, public Sale{
- private:
- int pages;
- public:
- Book(): pages(0) { Publication2(); Sale();}
- Book(string a, double b, int c, int dd, int mm, int yy, float x, float y, float z): pages(c) { Publication2(a, b, dd, mm, yy); Sale(x, y, z);}
- ~Book() {}
- void read() {
- Publication2::read();
- Sale::read();
- cout << left << setw(22) << "Enter the Number of Pages: ";
- cin >> pages;
- }
- void show() {
- Publication2::show();
- Sale::show();
- cout << left << setw(22) << "Number of Pages: " << pages << endl;
- }
- };
- class Tape: public Publication2, public Sale{
- private:
- double duration;
- public:
- Tape(): duration(0) { Publication2(); Sale();}
- Tape(string a, double b, double c, int dd, int mm, int yy, float x, float y, float z): duration(c) { Publication2(a, b, dd, mm, yy); Sale(x, y, z);}
- ~Tape() {}
- void read() {
- Publication2::read();
- Sale::read();
- cout << left << setw(22) << "Enter the Duration: ";
- cin >> duration;
- }
- void show() {
- Publication2::show();
- Sale::show();
- cout << left << setw(22) << "Duration: " << duration << endl;
- }
- };
- int main() {
- Publication P;
- P.read();
- cout << endl;
- P.show();
- cout << endl << endl;
- Publication2 P2;
- P2.read();
- cout << endl;
- P2.show();
- cout << endl << endl;
- Book B;
- B.read();
- cout << endl;
- B.show();
- cout << endl << endl;
- Tape T;
- T.read();
- cout << endl;
- T.show();
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement