Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <iterator>
  4. using namespace std;
  5. struct flat{
  6.     int room;
  7.     string district;
  8.     int footage;
  9.     int floor;
  10.     flat(){
  11.         room = 0;
  12.         district ="";
  13.         footage = 0;
  14.         floor = 0;
  15.     }
  16. };
  17. class client{
  18.     string name;
  19.     static int id;
  20.     int ID;
  21.     flat want;
  22.     flat exist;
  23.     public:
  24.     client(){
  25.         cout << "\nEnter name: ";
  26.         cin >> name;
  27.         cout << "Enter information about wanted flat\n";
  28.         cout << "Count of room: ";
  29.         cin >> want.room;
  30.         cout << "Floor: ";
  31.         cin >> want.floor;
  32.         cout << "District: ";
  33.         cin >> want.district;
  34.         cout << "Square: ";
  35.         cin >> want.footage;
  36.         cout << "\nEnter information about existed flat\n";
  37.         cout << "Count of room: ";
  38.         cin >> exist.room;
  39.         cout << "Floor: ";
  40.         cin >> exist.floor;
  41.         cout << "District: ";
  42.         cin >> exist.district;
  43.         cout << "Footage: ";
  44.         cin >> exist.footage;
  45.         id++;
  46.         ID = id;
  47.     }
  48.     void print(){
  49.        
  50.             cout<<"\t  client name - "<<name<<" id - "<<ID<<"\n\n";
  51.             cout<<" Exsiting flat\t\t\t Want flat";
  52.             cout<<"\nDistrict - "<<exist.district<<"\t\t\t"<<"District - "<<want.district;
  53.             cout<<"\nRoom - "<<exist.room<<"\t\t\t"<<"Room - "<<want.room;
  54.             cout<<"\nFloor - "<<exist.floor<<"\t\t\t"<<"Floor - "<<want.floor;
  55.             cout<<"\nFootage - "<<exist.footage<<"\t\t\t"<<"Footage - "<<want.footage;
  56.             cout<<"\n_______________________________________________\n";
  57.     }
  58.     friend bool compare(client &obj1 , client &obj2);
  59. };
  60.     bool compare(client &obj1 ,client &obj2){
  61.         if (obj1.exist.floor == obj2.want.floor &&
  62.         obj1.exist.district == obj2.want.district &&
  63.         obj1.exist.room == obj2.want.room &&
  64.         (obj1.exist.footage*0.9 <= obj2.want.footage && obj1.exist.footage*1.1 >= obj2.want.footage) &&
  65.         obj1.want.floor == obj2.exist.floor &&
  66.         obj1.want.district == obj2.exist.district &&
  67.         obj1.want.room == obj2.exist.room &&
  68.         (obj1.want.footage*0.9 <= obj2.exist.footage && obj1.want.footage*1.1 >= obj2.exist.footage)
  69.         )
  70.         return true;
  71.         else
  72.         return false;
  73.     }
  74. int client::id;
  75. void print(list<client*> list){
  76.     for (auto v : list){
  77.         v->print();
  78.     }
  79. }
  80. int main(int argc, char *argv[]) {
  81.     list<client*> list;
  82.    
  83.     while (true)
  84.     {
  85.         int  choice;
  86.         printf("\n2)Push \n3)Print all list data \n3)Exit\n");
  87.         scanf("%d", &choice);
  88.         switch (choice)
  89.         {
  90.         case 1:
  91.             list.push_back(new client);
  92.             break;
  93.         case 2:
  94.             list.push_back(new client);
  95.             for (auto iterator = list.begin(); iterator != prev(list.end()); ++iterator) {
  96.  
  97.                 if (compare(**iterator, *list.back())) {
  98.                     cout<<"flats swapped\n";
  99.                     list.pop_back();
  100.                     list.remove(*iterator);
  101.                     break;
  102.                 }else {
  103.  
  104.             }
  105.             break;
  106.         }
  107.            
  108.         case 3:
  109.             print(list);
  110.             break;
  111.         case 4:
  112.             exit(0);
  113.             break;
  114.         default:
  115.             cout<<"ti bidlo";
  116.             break;
  117.         }
  118.     }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement