Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. struct rezume{
  5.     char name[30];
  6.     int age;
  7.     int study;
  8.     int kitchen[4];
  9.     int experience;
  10.     int max_experience_one_place;
  11.     int number_change_work;
  12.     int dismiss_from_kitchen;
  13. };
  14. int  main() {
  15.     ifstream input("C:\\Users\\user\\CLionProjects\\ex1\\restaurant.txt");
  16.     ofstream bin_output("C:\\Users\\user\\CLionProjects\\rttt\\employers_top.bin", ios::out|ios::binary);
  17.     rezume applicants;
  18.     auto *chef = new rezume[100];
  19.     int n;
  20.     cout<<"enter number applicants  n = "<<endl;
  21.     cin>>n;
  22.     if(!input){
  23.         cout<<"Can't open file";
  24.         exit(-1);
  25.     }
  26.     int i=0;
  27.     while( input>>applicants.name>>applicants.age>>applicants.study>>applicants.kitchen[0]>>applicants.kitchen[1]
  28.                 >>applicants.kitchen[2]>>applicants.kitchen[3]>>applicants.experience>>applicants.max_experience_one_place
  29.                 >>applicants.number_change_work>>applicants.dismiss_from_kitchen) {
  30.         if((applicants.age<50)&&(applicants.study==1||applicants.study==2)&&(applicants.kitchen[0]==1||applicants.kitchen[1]==1)
  31.            &&(applicants.experience>=5)&&(applicants.max_experience_one_place*2>=applicants.experience)&&(applicants.number_change_work<=5)
  32.            &&(applicants.dismiss_from_kitchen<=1)){
  33.             chef[i]=applicants;
  34.             i++;
  35.         }
  36.     }
  37.     input.close();
  38.     for (int j=0; j < i; j++) {
  39.         for (int k=j+1; k < i; k++) {
  40.             if (chef[j].experience < chef[k].experience) {
  41.                 applicants = chef[j];
  42.                 chef[j] = chef[k];
  43.                 chef[k] = applicants;
  44.             }
  45.         }
  46.     }
  47.     if (i < n) {
  48.         cout << "Pretendents less necessory!";
  49.         exit(1);
  50.     }
  51.     for(i=0;i<n;i++) {
  52.         bin_output.write((char *) &chef[i], sizeof(struct rezume));
  53.     }
  54.     bin_output.close();
  55.     bool p = false;
  56.     ifstream bin_input("C:\\Users\\user\\CLionProjects\\rttt\\employers_top.bin", ios::in|ios::binary);
  57.     for (int i = 0; i <n ; ++i) {
  58.         bin_input.read((char *) &applicants, sizeof(struct rezume));
  59.         if ((applicants.age <= 45) && (applicants.study == 2) && (applicants.experience >= 15) &&
  60.             (applicants.dismiss_from_kitchen == 0) && (applicants.number_change_work <= 2)) {
  61.             p = true;
  62.             cout << applicants.name << ' ' << applicants.age <<' ' << endl;
  63.         }
  64.     }
  65.     bin_input.close();
  66.     if (!p){
  67.         cout << "Sorry! Chief cook is not appeared!" << endl; //
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement