Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- using namespace std;
- class publication
- {
- protected:
- string name;
- float price;
- public:
- publication(): price(0), name("N/A") {}
- void putdata()
- {
- cout << "Name: "; cin >> name;
- cout << "Price: "; cin >> price;
- }
- void getdata() const
- {
- cout << "Name: " << name << "\n";
- cout << "Price: " << price << "\n";
- }
- };
- class sales
- {
- protected:
- float sal[3];
- public:
- sales() {sal[0] = 0, sal[1] = 0; sal[2] = 0;}
- sales(float a, float b, float c) {sal[0] = a; sal[1] = b; sal[2] = c;}
- void putdata()
- {
- cout << "Sales month ago: "; cin >> sal[0];
- cout << "Sales 2 months ago: "; cin >> sal[1];
- cout << "Sales 3 months ago: "; cin >> sal[2];
- }
- void getdata() const
- {
- cout << "Sales month ago: " << sal[0] << "\n";
- cout << "Sales 2 months ago: " << sal[1] << "\n";
- cout << "Sales 3 months ago: " << sal[2] << "\n";
- }
- };
- class book: public publication, public sales
- {
- protected:
- int num;
- public:
- book(): num(0), publication() {}
- void putdata()
- {
- publication::putdata();
- cout << "Number of pages: "; cin >> num;
- sales::putdata();
- }
- void getdata() const
- {
- publication::getdata();
- cout << "Number of pages: " << num << "\n";
- sales::getdata();
- }
- };
- class type: public publication, public sales
- {
- protected:
- float time;
- public:
- type(): time(0), publication() {}
- void putdata()
- {
- publication::putdata();
- cout << "Length of record: "; cin >> time;
- sales::putdata();
- }
- void getdata()
- {
- publication::getdata();
- cout << "Length of record: " << time << "\n";
- sales::getdata();
- }
- };
- class disk: public publication, public sales
- {
- protected:
- enum type_disk{dvd, cd};
- type_disk Disk;
- public:
- disk(): publication(), sales() {}
- void putdata()
- {
- publication::putdata();
- sales::putdata();
- cout << "Disk type(cd, dvd): ";
- string temp; cin >> temp;
- while (!(temp == "cd" or temp == "dvd"))
- {
- cout << "Error, try again \nDisk type(cd, dvd): ";
- cin >> temp;
- }
- if (temp == "dvd") Disk = dvd;
- else
- {
- if (temp == "cd") Disk = cd;
- else {cout << "Unexpecter error!"; exit(11);}
- }
- }
- void getdata() const
- {
- publication::getdata();
- sales::getdata();
- cout << "Disk type(CD, DVD): ";
- if (Disk == cd) cout << "cd" << "\n";
- else cout << "dvd" << "\n";
- }
- };
- int main()
- {
- book book1;
- type type1;
- disk disk1;
- cout << "Book 1:\n";
- book1.putdata();
- cout << "\nRecord 1:\n";
- type1.putdata();
- cout << "\nDisk 1:\n";
- disk1.putdata();
- cout << "\n";
- book1.getdata();
- cout << "\n";
- type1.getdata();
- cout << "\n";
- disk1.getdata();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement