Lab10_NotReady
unknown
c_cpp
3 years ago
3.6 kB
5
Indexable
#include <iostream> #include <cstring> using namespace std; const int StrLen = 250; class Building { private: char Adress[20]; char Type[15]; int Lifetime; int RenovationTerm; int Floors; Building* Next = 0; public: char* GetAdress() { return Adress; } char* GetType() { return Type; } int GetLifetime() { return Lifetime; } int GetRenovationTerm() { return RenovationTerm; } int GetFloors() { return Floors; } Building* GetNext() { return Next; } void SetAdress(char* title) { strcpy(Adress, title); } void SetType(char* authorName) { strcpy(Type, authorName); } void SetLifetime(int lifetime) { Lifetime = lifetime; } void SetRenovationTerm(int renovationTerm) { RenovationTerm = renovationTerm; } void SetFloors(int floors) { Floors = floors; } void SetNext(Building* next) { Next = next; } }; istream& operator>>(istream& stream, Building& obj) { char str[StrLen]; cout << "\nEnter adress: "; cin.getline(str, StrLen); obj.SetAdress(str); cout << "\nEnter the type of building: "; cin.getline(str, StrLen); obj.SetType(str); int lifetime; cout << "\nEnter building lifetime: "; cin >> lifetime; obj.SetLifetime(lifetime); obj.SetRenovationTerm(25 - lifetime); int floors; cout << "\nEnter building floors"; cin >> floors; obj.SetFloors(floors); cin.ignore(); return stream; } ostream& operator<<(ostream& stream, Building& obj) { stream << " " << obj.GetAdress() << " " << obj.GetType() << " " << obj.GetLifetime() << " " << obj.GetFloors(); return stream; } Building *CreateList(int); void DisplayList(Building*); void DisplayChoise(Building*, char*, int, int); void DeleteList(Building*); int main() { int dimension; char type[15]; int lowerFloor, higherFloor; cout << "Enter the number of buildings: "; cin >> dimension; Building beginList = CreateList(dimension); cout << "\nThe list of buildings: \n"; DisplayList(beginList); cout << "\nEnter the type of building: " cin.getline(type, StrLen); cout << "\nEnter lower floor: "; cin >> lowerFloor; cout << "\nEnter highter floor: "; cin >> higherFloor; DisplayChoise(beginList, type, lowerFloor, higherFloor); DeleteList(beginList); return 0; } Building* CreateList(int n) { Building* beginList = new Building; cout << "Enter information about 1-th building: " << endl; cin.ignore(); cin >> (*beginList); Building* current = beginList; for (int i = 1; i < n; i++) { Building* next = current->GetNext(); next = new Building; cin >> (*next); current = next; } return beginList; } void DisplayList(Building* beginList) { Building* current = beginList; while(current) { cout << (*current) << endl; current = current->GetNext(); } } void DisplayChoise(Building* beginList, char* type, int lowerFloor, int higherFloor) { Building* current = beginList; while (current) { if (strcmp(current->GetType(), type) == 0 && current->GetFloors() > lowerFloor && current->GetFloors() <= higherFloor) cout << (*current); current = current->GetNext(); } } void DeleteList(Building *beginList) { Building* current = beginList; while (current) { beginList = current->GetNext(); delete current; current = beginList; } }
Editor is loading...