Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Republic{
- protected:
- string name;
- public:
- static Republic * begin;
- Republic * next;
- static void add(Republic *cur){
- cur->next = begin;
- begin = cur;
- }
- Republic(){
- add(this);
- }
- virtual void show(){
- cout << "Name: " << name << endl;
- cout << "----------------------------" << endl;
- }
- virtual void set_parameters(){
- string s;
- cout << "Name: ";
- cin >> s;
- name = s;
- }
- virtual void print() {
- Republic *l = begin;
- while (l) {
- l->show();
- l = l->next;
- }
- }
- };
- Republic * Republic::begin;
- class Monarh: public Republic{
- protected:
- int peop;
- string lang;
- public:
- Monarh():Republic(){}
- void show() {
- cout << "Name: " << name << endl;
- cout << "People: " << peop << endl;
- cout << "Language: " << lang << endl;
- cout << "----------------------------" << endl;
- }
- void set_parameters() {
- int k;
- string s, a;
- cout << "Name: ";
- cin >> s;
- cout << "People: ";
- cin >> k;
- cout << "Language: ";
- cin>>a;
- name = s;
- peop = k;
- lang=a;
- }
- };
- class Kingdom: public Republic{
- protected:
- int peop;
- public:
- Kingdom():Republic(){}
- void show(){
- cout << "Name: " << name << endl;
- cout << "People: " << peop << endl;
- cout << "----------------------------" << endl;
- }
- void set_parameters(){
- int n;
- string s;
- cout << "Name: ";
- cin >> s;
- cout << "People: ";
- cin >> n;
- name = s;
- peop = n;
- }
- };
- class State: public Republic{
- public:
- State():Republic(){}
- };
- int main(){
- Republic::begin = 0;
- Republic republic;
- Monarh monarch;
- Kingdom kingdom;
- State state;
- cout << "Republic" << endl;
- republic.set_parameters();
- cout << "Monarch" << endl;
- monarch.set_parameters();
- cout << "Kingdom" << endl;
- kingdom.set_parameters();
- cout << "State" << endl;
- state.set_parameters();
- cout << "============================" << endl;
- cout << "All REPUBLIC" << endl;
- cout << "============================" << endl;
- republic.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement