Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Transport{
- protected:
- string name;
- public:
- static Transport * begin;
- Transport * next;
- static void add(Transport *cur){
- cur->next = begin;
- begin = cur;
- }
- Transport(){
- add(this);
- }
- virtual void show(){
- cout << "Transport: " << name << endl;
- cout << "----------------------------" << endl;
- }
- virtual void set_parameters(){
- string s;
- cout << "Transport: ";
- cin >> s;
- name = s;
- }
- virtual void print() {
- Transport *l = begin;
- while (l) {
- l->show();
- l = l->next;
- }
- }
- };
- Transport * Transport::begin;
- class Auto: public Transport{
- protected:
- int horsepower;
- string model;
- public:
- Auto():Transport(){}
- void show() {
- cout << "Transport: " << name << endl;
- cout << "Horsepower: " << horsepower << endl;
- cout << "Model: " << model << endl;
- cout << "----------------------------" << endl;
- }
- void set_parameters() {
- int k;
- string s, a;
- cout << "Transport: ";
- cin >> s;
- cout << "Model: ";
- cin >> a;
- cout << "Horsepower: ";
- cin>>k;
- name = s;
- model = s;
- horsepower=k;
- }
- };
- class Train: public Transport{
- protected:
- int vagon;
- int weight;
- string type;
- public:
- Train():Transport(){}
- void show(){
- cout << "Transport: " << name << endl;
- cout << "Vagon: " << vagon << endl;
- cout << "Weight: " << weight << endl;
- cout << "Type:" << type << endl;
- cout << "----------------------------" << endl;
- }
- void set_parameters(){
- int n, m;
- string s,y;
- cout << "Name: ";
- cin >> s;
- cout << "Vagon: ";
- cin >> n;
- cout << "Weight: ";
- cin>>m;
- cout << "Type: ";
- cin>>y;
- name = s;
- vagon = n;
- type = y;
- weight = m;
- }
- };
- class Express: public Transport{
- public:
- Express():Transport(){}
- };
- int main(){
- Transport::begin = 0;
- Transport transport;
- Auto auto_;
- Train train;
- Express express;
- cout << "Transport" << endl;
- transport.set_parameters();
- cout << "Auto" << endl;
- auto_.set_parameters();
- cout << "Train" << endl;
- train.set_parameters();
- cout << "Express" << endl;
- express.set_parameters();
- cout << endl;
- cout << "All TRANSPORT" << endl;
- cout << endl;
- transport.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement