Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <iterator>
- using namespace std;
- struct flat{
- int room;
- string district;
- int footage;
- int floor;
- flat(){
- room = 0;
- district ="";
- footage = 0;
- floor = 0;
- }
- };
- class client{
- string name;
- static int id;
- int ID;
- flat want;
- flat exist;
- public:
- client(){
- cout << "\nEnter name: ";
- cin >> name;
- cout << "Enter information about wanted flat\n";
- cout << "Count of room: ";
- cin >> want.room;
- cout << "Floor: ";
- cin >> want.floor;
- cout << "District: ";
- cin >> want.district;
- cout << "Square: ";
- cin >> want.footage;
- cout << "\nEnter information about existed flat\n";
- cout << "Count of room: ";
- cin >> exist.room;
- cout << "Floor: ";
- cin >> exist.floor;
- cout << "District: ";
- cin >> exist.district;
- cout << "Footage: ";
- cin >> exist.footage;
- id++;
- ID = id;
- }
- void print(){
- cout<<"\t client name - "<<name<<" id - "<<ID<<"\n\n";
- cout<<" Exsiting flat\t\t\t Want flat";
- cout<<"\nDistrict - "<<exist.district<<"\t\t\t"<<"District - "<<want.district;
- cout<<"\nRoom - "<<exist.room<<"\t\t\t"<<"Room - "<<want.room;
- cout<<"\nFloor - "<<exist.floor<<"\t\t\t"<<"Floor - "<<want.floor;
- cout<<"\nFootage - "<<exist.footage<<"\t\t\t"<<"Footage - "<<want.footage;
- cout<<"\n_______________________________________________\n";
- }
- friend bool compare(client &obj1 , client &obj2);
- };
- bool compare(client &obj1 ,client &obj2){
- if (obj1.exist.floor == obj2.want.floor &&
- obj1.exist.district == obj2.want.district &&
- obj1.exist.room == obj2.want.room &&
- (obj1.exist.footage*0.9 <= obj2.want.footage && obj1.exist.footage*1.1 >= obj2.want.footage) &&
- obj1.want.floor == obj2.exist.floor &&
- obj1.want.district == obj2.exist.district &&
- obj1.want.room == obj2.exist.room &&
- (obj1.want.footage*0.9 <= obj2.exist.footage && obj1.want.footage*1.1 >= obj2.exist.footage)
- )
- return true;
- else
- return false;
- }
- int client::id;
- void print(list<client*> list){
- for (auto v : list){
- v->print();
- }
- }
- int main(int argc, char *argv[]) {
- list<client*> list;
- while (true)
- {
- int choice;
- printf("\n2)Push \n3)Print all list data \n3)Exit\n");
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- list.push_back(new client);
- break;
- case 2:
- list.push_back(new client);
- for (auto iterator = list.begin(); iterator != prev(list.end()); ++iterator) {
- if (compare(**iterator, *list.back())) {
- cout<<"flats swapped\n";
- list.pop_back();
- list.remove(*iterator);
- break;
- }else {
- }
- break;
- }
- case 3:
- print(list);
- break;
- case 4:
- exit(0);
- break;
- default:
- cout<<"ti bidlo";
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement