Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include "ApartList.h"
  2. #include "string"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. ApartList::ApartList()
  8. : start(NULL)
  9. , pcur(NULL)
  10. , n(0)
  11. {
  12. }
  13.  
  14.  
  15. ApartList::~ApartList()
  16. {
  17. }
  18.  
  19. // конструктор с параметрами
  20. ApartList::ApartList(int n1)
  21. {
  22. ApartElem* tmp;
  23. ApartElem* cur;
  24. n = n1;
  25. for (int i = 0; i < n; i++)
  26. {
  27. tmp = new ApartElem;
  28. tmp->Input();
  29. if (i == 0)
  30. {
  31. start = cur = tmp;
  32. start->SetNext(NULL);
  33. }
  34. else
  35. {
  36. tmp->SetNext(start);
  37. start = tmp;
  38. }
  39. }
  40. }
  41.  
  42.  
  43. // Печать
  44. void ApartList::Print()
  45. {
  46. ApartElem* cur;
  47. cout << "\nИНФОРМАЦИЯ О КВАРТИРАХ\n";
  48. for (cur = start; cur != NULL; cur = cur->GetNext())
  49. cur->Print();
  50. }
  51.  
  52. void ApartList::BalconTwo()
  53. {
  54. ApartElem* cur;
  55. for (cur = start; cur != NULL; cur = cur->GetNext())
  56. {
  57. if ((stoi(cur->GetStage()) > 1) && cur->GetBalcony())
  58. {
  59. cur->Print();
  60. }
  61. }
  62. }
  63.  
  64. void ApartList::PrintStage(string St)
  65. {
  66. ApartElem* cur;
  67. for (cur = start; cur != NULL; cur = cur->GetNext())
  68. {
  69. if (stoi(cur->GetStage()) == stoi(St))
  70. {
  71. cur->Print();
  72. }
  73. }
  74. }
  75.  
  76. void ApartList::Find()
  77. {
  78. ApartElem* cur;
  79. bool NoFind = true;
  80. string num; // Этаж
  81. string am; // Количество комнат
  82. string sq; // Площадь
  83. string bal; // балкон
  84. ApartElem* rofl = NULL;
  85.  
  86. getline(cin, num);
  87. getline(cin, am);
  88. getline(cin, sq);
  89. getline(cin, bal);
  90.  
  91. for (cur = start; cur != NULL; cur = cur->GetNext())
  92. {
  93. // stoi() - переводит строку по типу "23" в целочисленный тип данных int = 23
  94. if (((cur->stage) == num) && ((cur->amount) == am) && ((stoi(cur->area)) >= (stoi(sq) * 0.9)) && ((stoi(cur->area)) <= (stoi(sq) * 1.1)))
  95. {
  96. if (((bal == "Да") || (bal == "да")) && cur->GetBalcony())// Если пользователь ввел Да и балкон правда есть
  97. {
  98. NoFind = false;
  99. cout << "Найденная квартира по заданным критериям:\n";
  100. cur->Print();
  101. break;
  102. }
  103. else if(((bal == "Нет") || (bal == "нет")) && !cur->GetBalcony()) // Если ввел Нет и балкона нет
  104. {
  105. NoFind = false;
  106. cout << "Найденная квартира по заданным критериям:\n";
  107. cur->Print();
  108. break;
  109. }
  110. }
  111. }
  112.  
  113. if (NoFind)
  114. {
  115. cout << "Квартира не найдена.";
  116. }
  117.  
  118. }
  119. // Добавление в начало
  120. ApartList* ApartList::operator++(int a)
  121. {
  122.  
  123. ApartElem*Tmp;
  124. Tmp = new ApartElem;
  125. Tmp->Input();
  126. Tmp->SetNext(start);
  127. start = Tmp;
  128. n++;
  129. return this;
  130. }
  131. // Ввод
  132. void ApartList::Input()
  133. {
  134. ApartElem* tmp;
  135. ApartElem* cur;
  136. cout << "Введите количество квартир:\t";
  137. cin >> n;
  138. for (int i = 0; i < n; i++)
  139. {
  140. tmp = new ApartElem;
  141. tmp->Input();
  142. if (i == 0)
  143. {
  144. start = cur = tmp;
  145. start->SetNext(NULL);
  146. }
  147. else
  148. {
  149. tmp->SetNext(start);
  150. start = tmp;
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement