Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ApartList.h"
- #include "string"
- #include <iostream>
- using namespace std;
- ApartList::ApartList()
- : start(NULL)
- , pcur(NULL)
- , n(0)
- {
- }
- ApartList::~ApartList()
- {
- }
- // конструктор с параметрами
- ApartList::ApartList(int n1)
- {
- ApartElem* tmp;
- ApartElem* cur;
- n = n1;
- for (int i = 0; i < n; i++)
- {
- tmp = new ApartElem;
- tmp->Input();
- if (i == 0)
- {
- start = cur = tmp;
- start->SetNext(NULL);
- }
- else
- {
- tmp->SetNext(start);
- start = tmp;
- }
- }
- }
- // Печать
- void ApartList::Print()
- {
- ApartElem* cur;
- cout << "\nИНФОРМАЦИЯ О КВАРТИРАХ\n";
- for (cur = start; cur != NULL; cur = cur->GetNext())
- cur->Print();
- }
- void ApartList::BalconTwo()
- {
- ApartElem* cur;
- for (cur = start; cur != NULL; cur = cur->GetNext())
- {
- if ((stoi(cur->GetStage()) > 1) && cur->GetBalcony())
- {
- cur->Print();
- }
- }
- }
- void ApartList::PrintStage(string St)
- {
- ApartElem* cur;
- for (cur = start; cur != NULL; cur = cur->GetNext())
- {
- if (stoi(cur->GetStage()) == stoi(St))
- {
- cur->Print();
- }
- }
- }
- void ApartList::Find()
- {
- ApartElem* cur;
- bool NoFind = true;
- string num; // Этаж
- string am; // Количество комнат
- string sq; // Площадь
- string bal; // балкон
- ApartElem* rofl = NULL;
- getline(cin, num);
- getline(cin, am);
- getline(cin, sq);
- getline(cin, bal);
- for (cur = start; cur != NULL; cur = cur->GetNext())
- {
- // stoi() - переводит строку по типу "23" в целочисленный тип данных int = 23
- if (((cur->stage) == num) && ((cur->amount) == am) && ((stoi(cur->area)) >= (stoi(sq) * 0.9)) && ((stoi(cur->area)) <= (stoi(sq) * 1.1)))
- {
- if (((bal == "Да") || (bal == "да")) && cur->GetBalcony())// Если пользователь ввел Да и балкон правда есть
- {
- NoFind = false;
- cout << "Найденная квартира по заданным критериям:\n";
- cur->Print();
- break;
- }
- else if(((bal == "Нет") || (bal == "нет")) && !cur->GetBalcony()) // Если ввел Нет и балкона нет
- {
- NoFind = false;
- cout << "Найденная квартира по заданным критериям:\n";
- cur->Print();
- break;
- }
- }
- }
- if (NoFind)
- {
- cout << "Квартира не найдена.";
- }
- }
- // Добавление в начало
- ApartList* ApartList::operator++(int a)
- {
- ApartElem*Tmp;
- Tmp = new ApartElem;
- Tmp->Input();
- Tmp->SetNext(start);
- start = Tmp;
- n++;
- return this;
- }
- // Ввод
- void ApartList::Input()
- {
- ApartElem* tmp;
- ApartElem* cur;
- cout << "Введите количество квартир:\t";
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- tmp = new ApartElem;
- tmp->Input();
- if (i == 0)
- {
- start = cur = tmp;
- start->SetNext(NULL);
- }
- else
- {
- tmp->SetNext(start);
- start = tmp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement