gashink_t

наследование и полиморфизм(ТП лаба.6)

Mar 19th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class information { //супер класс игфлрмации об организациях
  6.     protected: string name, activity,address;
  7.     public: information(string na, string activ, string addr) {
  8.                 name=na;
  9.                 activity=activ;
  10.                 address=addr;
  11.             }
  12.             void inf_out() {
  13.                 cout << "Name of the organization: " << name << endl;
  14.                 cout << "Type of activity: " << activity << endl;
  15.                 cout << "Legal address: " << address << endl<< endl;
  16.             }
  17. };
  18. class theater: public information { //подкласс театр
  19.     private: int capacity;
  20.     public: theater (string na, string activ, string addr, int c): information(na,activ,addr) {
  21.                 name=na;
  22.                 activity=activ;
  23.                 address=addr;
  24.                 capacity=c;
  25.             }
  26.             void capacity_out() {
  27.                 cout << "Capacity: " << capacity << endl;
  28.             }
  29. };
  30. class cafe: public information { // подкласс кафе
  31.     private: int capacity;
  32.     public: cafe(string na, string activ, string addr, int c): information(na,activ,addr) {
  33.             name=na;
  34.             activity=activ;
  35.             address=addr;
  36.             capacity=c;
  37.         }
  38.         void capacity_out() {
  39.             cout << "Capacity: " << capacity << endl;
  40.         }
  41. };
  42.  
  43. int main() {
  44.     information* org1 = new information("showroom 'Lime'", "commercial","NSK, Lenino, 24/3");
  45.     theater* org2 = new theater("Opera and ballet theater", "commercial","Moscow, Frundze, 2/56", 1329);
  46.     cafe* org3 = new cafe("Pop cafe", "commercial","Irkutsk, Mechurina, 16/1", 41);
  47.     org1->inf_out();
  48.     org2->inf_out();
  49.     org2->capacity_out();
  50.     org3->inf_out();
  51.     org3->capacity_out();
  52.     return 0;
  53. }
Add Comment
Please, Sign In to add comment