Advertisement
Guest User

Untitled

a guest
May 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class engine
  7. {
  8. protected:
  9.     float power, height, width;
  10. public:
  11.     engine *nast;
  12.     engine();
  13.     engine(float p, float h, float w);
  14.     engine(engine &e);
  15.     void setPower(float p) { power = p; }
  16.     void setHeight(float h) { height = h; }
  17.     void setWidth(float w) { width = w; }
  18.     float getPower() { return power; }
  19.     float getHeight() { return height; }
  20.     float getWidth() { return width; }
  21.     void getAll()
  22.     {
  23.         printf("Power: %0.2f\nHeight: %0.2f\nWidth: %0.2f\n", power, height, width);
  24.     }
  25.     ~engine();
  26. };
  27. engine::engine()
  28. {
  29.     power = 1.0;
  30.     height = 1.0;
  31.     width = 1.0;
  32. }
  33. engine::engine(float p, float h, float w)
  34. {
  35.     power = p;
  36.     height = h;
  37.     width = w;
  38. }
  39. engine::engine(engine &e)
  40. {
  41.     power = e.getPower();
  42.     height = e.getHeight();
  43.     width = e.getWidth();
  44. }
  45. engine::~engine()
  46. {
  47.     delete nast;
  48. }
  49. class car
  50. {
  51. protected:
  52.     float price;
  53.     char *type;
  54. public:
  55.     car *nast;
  56.     car();
  57.     car(float p, char *t);
  58.     car(car &c);
  59.     void setPrice(float p) { price = p; }
  60.     void setType(char *s) { type = s; }
  61.     float getPrice() { return price; }
  62.     char *getType() { return type; }
  63.     void getAll()
  64.     {
  65.         printf("Price: %0.2f\nType: %s\n", price, type);
  66.     }
  67.     ~car();
  68. };
  69. car::car()
  70. {
  71.     price = 1.0;
  72.     type = "osobowy";
  73. }
  74. car::car(float p, char *t)
  75. {
  76.     price = p;
  77.     type = t;
  78. }
  79. car::car(car &c)
  80. {
  81.     price = c.getPrice();
  82.     type = c.getType();
  83. }
  84. car::~car()
  85. {
  86.     delete nast;
  87. }
  88. class optic
  89. {
  90. protected:
  91.     int zoom;
  92.     float weight;
  93. public:
  94.     optic *nast;
  95.     optic();
  96.     optic(int z, float w);
  97.     optic(optic &o);
  98.     void setZoom(int z) { zoom = z; }
  99.     void setWeight(float w) { weight = w; }
  100.     int getZoom() { return zoom; }
  101.     float getWeight() { return weight; }
  102.     void getAll()
  103.     {
  104.         printf("Zoom: %d\nWeight: %0.2f\n", zoom, weight);
  105.     }
  106.     ~optic();
  107. };
  108.  
  109. optic::optic()
  110. {
  111.     zoom = 1;
  112.     weight = 1.0;
  113. }
  114. optic::optic(int z, float w)
  115. {
  116.     zoom = z;
  117.     weight = w;
  118. }
  119. optic::optic(optic &o)
  120. {
  121.     zoom = o.getZoom();
  122.     weight = o.getWeight();
  123. }
  124. optic::~optic()
  125. {
  126.     delete nast;
  127. }
  128. class person
  129. {
  130. protected:
  131.     char *name, *surrname, *email;
  132. public:
  133.     person *nast;
  134.     person();
  135.     person(char *n, char *s, char *e);
  136.     person(person &p);
  137.     void setName(char *s) { name = s; }
  138.     void setSurrname(char *s) { surrname = s; }
  139.     void setEmail(char *s) { email = s; }
  140.     char *getName() { return name; }
  141.     char *getSurrname() { return surrname; }
  142.     char *getEmail() { return email; }
  143.     void getAll()
  144.     {
  145.         printf("Name: %s\nSurrname: %s\nEmail: %s\n", name, surrname, email);
  146.     }
  147.     ~person();
  148. };
  149. person::person()
  150. {
  151.     name = "Mariusz";
  152.     surrname = "Podstawowy";
  153.     email = "konstruktor@gmail.com";
  154. }
  155. person::person(char *n, char *s, char *e)
  156. {
  157.     name = n;
  158.     surrname = s;
  159.     email = e;
  160. }
  161. person::person(person &p)
  162. {
  163.     name = p.getName();
  164.     surrname = p.getSurrname();
  165.     email = p.getEmail();
  166. }
  167. person::~person()
  168. {
  169.     delete nast;
  170. }
  171.  
  172. int main()
  173. {
  174.     optic *head = NULL, *wsk;
  175.     wsk = head;
  176.     for (int i = 0; i < 5; i++)
  177.     {
  178.         if (head == NULL)
  179.         {
  180.             head = wsk = new optic(5, 1.0);
  181.         }
  182.         else
  183.         {
  184.             wsk->nast = new optic();
  185.             wsk = wsk->nast;
  186.         }
  187.     }
  188.     wsk = head;
  189.     while (wsk != NULL)
  190.     {
  191.         wsk->getAll();
  192.         wsk = wsk->nast;
  193.     }
  194.     system("Pause");
  195.     return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement