Advertisement
evcamels

lr6

Nov 15th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Republic{
  7.     protected:
  8.         string name;
  9.  
  10.     public:
  11.         static Republic * begin;
  12.         Republic * next;
  13.        
  14.         static void add(Republic *cur){
  15.             cur->next = begin;
  16.             begin = cur;
  17.         }
  18.        
  19.         Republic(){
  20.             add(this);
  21.         }
  22.          
  23.     virtual void show(){
  24.         cout << "Name: " << name << endl;
  25.         cout << "----------------------------" << endl;
  26.     }
  27.    
  28.     virtual void set_parameters(){
  29.         string s;
  30.        
  31.         cout << "Name: ";
  32.         cin >> s;
  33.        
  34.         name = s;
  35.     }
  36.    
  37.     virtual void print() {
  38.         Republic *l = begin;
  39.        
  40.         while (l) {
  41.             l->show();
  42.             l = l->next;
  43.         }
  44.     }
  45. };
  46.  
  47.     Republic * Republic::begin;
  48.  
  49.     class Monarh: public Republic{
  50.     protected:
  51.         int peop;
  52.         string lang;
  53.  
  54.     public:
  55.         Monarh():Republic(){}
  56.        
  57.         void show() {
  58.             cout << "Name: " << name << endl;
  59.             cout << "People: " << peop << endl;
  60.             cout << "Language: " << lang << endl;
  61.             cout << "----------------------------" << endl;
  62.         }
  63.        
  64.         void set_parameters() {
  65.             int k;
  66.             string s, a;
  67.            
  68.             cout << "Name: ";
  69.             cin >> s;
  70.            
  71.             cout << "People: ";
  72.             cin >> k;
  73.  
  74.             cout << "Language: ";
  75.             cin>>a;
  76.  
  77.             name = s;
  78.             peop = k;
  79.             lang=a;
  80.         }
  81.      
  82. };
  83.  
  84.     class Kingdom: public Republic{
  85.     protected:
  86.         int peop;
  87.  
  88.     public:
  89.         Kingdom():Republic(){}
  90.        
  91.         void show(){
  92.             cout << "Name: " << name << endl;
  93.             cout << "People: " << peop << endl;
  94.             cout << "----------------------------" << endl;
  95.         }
  96.  
  97.         void set_parameters(){
  98.             int n;
  99.             string s;
  100.            
  101.             cout << "Name: ";
  102.             cin >> s;
  103.            
  104.             cout << "People: ";
  105.             cin >> n;
  106.            
  107.            
  108.             name = s;
  109.             peop = n;
  110.         }
  111. };
  112.  
  113. class State: public Republic{
  114.     public:
  115.         State():Republic(){}
  116. };
  117.  
  118. int main(){
  119.     Republic::begin = 0;
  120.     Republic republic;
  121.     Monarh monarch;
  122.     Kingdom kingdom;
  123.     State state;
  124.  
  125.     cout << "Republic" << endl;
  126.     republic.set_parameters();
  127.    
  128.     cout << "Monarch" << endl;
  129.     monarch.set_parameters();
  130.    
  131.     cout << "Kingdom" << endl;
  132.     kingdom.set_parameters();
  133.    
  134.     cout << "State" << endl;
  135.     state.set_parameters();
  136.    
  137.     cout << "============================" << endl;
  138.     cout << "All REPUBLIC" << endl;
  139.     cout << "============================" << endl;
  140.  
  141.     republic.print();
  142.     return 0;
  143. }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement