Advertisement
skb50bd

Lab7 - Pointers

Jul 9th, 2015
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. class Publication{
  8. protected:
  9.     string title;
  10.     double price;
  11. public:
  12.     Publication(): title("N/A"), price(0.0) {}
  13.     Publication(string a, double b): title(a), price(b) {}
  14.     ~Publication() {}
  15.  
  16.     void read() {
  17.         cout << left << setw(22) << "Enter Title: ";
  18.         cin.sync();
  19.         getline(cin, title);
  20.         cin.sync();
  21.  
  22.         cout << left << setw(22) << "Enter Price: ";
  23.         cin >> price;
  24.     }
  25.  
  26.     void show() {
  27.         cout << left << setw(22) << "Title: " << title << endl;
  28.         cout << left << setw(22) << "Price: " << price << endl;
  29.     }
  30. };
  31.  
  32.  
  33.  
  34. class Publication2: public Publication{
  35. protected:
  36.     int dd, mm, yy;
  37. public:
  38.     Publication2(): dd(0), mm(0), yy(0) { Publication();}
  39.     Publication2(string a, double b, int dd, int mm, int yy): dd(dd), mm(mm), yy(yy) { Publication(a, b);}
  40.     ~Publication2() {}
  41.  
  42.     void read() {
  43.         Publication::read();
  44.         cout << left << setw(22) << "Enter Release Date: ";
  45.         cin >> dd >> mm >> yy;
  46.     }
  47.  
  48.     void show() {
  49.         Publication::show();
  50.         cout << left << setw(22) << "Realease Date: " << dd << " " << mm << " " << yy << endl;
  51.     }
  52. };
  53.  
  54.  
  55.  
  56. class Sale{
  57. protected:
  58.     float amount[3];
  59. public:
  60.     Sale(): amount({0,0,0}) {}
  61.     Sale(float a, float b, float c): amount({a,b,c}) {}
  62.     ~Sale() {}
  63.  
  64.     void read() {
  65.         cout << left << setw(22) << "Enter Sales: ";
  66.         for (int i = 0; i < 3; i++)
  67.             cin >> amount[i];
  68.     }
  69.  
  70.     void show() {
  71.         cout << left << setw(22) << "Sales: ";
  72.         for (int i = 0; i < 3; i++)
  73.             cout << amount[i] << " ";
  74.         cout << endl;
  75.     }
  76. };
  77.  
  78.  
  79.  
  80. class Book: public Publication2, public Sale{
  81. private:
  82.     int pages;
  83. public:
  84.     Book(): pages(0) { Publication2(); Sale();}
  85.     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);}
  86.     ~Book() {}
  87.  
  88.     void read() {
  89.         Publication2::read();
  90.         Sale::read();
  91.         cout << left << setw(22) << "Enter the Number of Pages: ";
  92.         cin >> pages;
  93.     }
  94.  
  95.     void show() {
  96.         Publication2::show();
  97.         Sale::show();
  98.         cout << left << setw(22) << "Number of Pages: " << pages << endl;
  99.     }
  100. };
  101.  
  102.  
  103.  
  104. class Tape: public Publication2, public Sale{
  105. private:
  106.     double duration;
  107. public:
  108.     Tape(): duration(0) { Publication2(); Sale();}
  109.     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);}
  110.     ~Tape() {}
  111.  
  112.     void read() {
  113.         Publication2::read();
  114.         Sale::read();
  115.         cout << left << setw(22) << "Enter the Duration: ";
  116.         cin >> duration;
  117.     }
  118.  
  119.     void show() {
  120.         Publication2::show();
  121.         Sale::show();
  122.         cout << left << setw(22) << "Duration: " << duration << endl;
  123.     }
  124. };
  125.  
  126.  
  127.  
  128. int main() {
  129.     Publication P;
  130.     P.read();
  131.     cout << endl;
  132.     P.show();
  133.     cout << endl << endl;
  134.  
  135.     Publication2 P2;
  136.     P2.read();
  137.     cout << endl;
  138.     P2.show();
  139.     cout << endl << endl;
  140.  
  141.     Book B;
  142.     B.read();
  143.     cout << endl;
  144.     B.show();
  145.     cout << endl << endl;
  146.  
  147.     Tape T;
  148.     T.read();
  149.     cout << endl;
  150.     T.show();
  151.     cout << endl << endl;
  152.  
  153.     return 0;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement