Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 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\\ilgam\\CLionProjects\\exam_task_1\\rezume");
  16. rezume applicants;
  17. auto *chef = new rezume[100];
  18. int n;
  19. cout<<"enter number applicants n = ";
  20. cin>>n;
  21. cout<<endl;
  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. for (int j=0; j < i; j++) {
  38. for (int k=j+1; k < i; k++) {
  39. if (chef[j].experience < chef[k].experience) {
  40. applicants = chef[j];
  41. chef[j] = chef[k];
  42. chef[k] = applicants;
  43. }
  44. }
  45. }
  46. if (i < n) {
  47. cout << "Pretendents less necessory!";
  48. exit(1);
  49. }
  50. ofstream bin_output("C:\\Users\\ilgam\\CLionProjects\\exam_task_1\\rezume.bin", ios::out|ios::binary);
  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. //auto *chef_top= new rezume[10];
  57. ifstream bin_input("C:\\Users\\ilgam\\CLionProjects\\exam_task_1\\rezume.bin", ios::in|ios::binary);
  58. for (int i = 0; i <n ; ++i) {
  59. bin_input.read((char *) &chef[i], sizeof(struct rezume));
  60. }
  61. for (i = 0; i < n; i++) { //
  62. if ((chef[i].age <= 45) && (chef[i].study == 2) && (chef[i].experience >= 15) &&
  63. (chef[i].dismiss_from_kitchen == 0) && (chef[i].number_change_work <= 2)) {
  64. p = true;
  65. cout << chef[i].name << ' ' << chef[i].age <<' ' << endl;
  66. }
  67. }
  68. bin_input.close();
  69. if (!p){
  70. cout << "Sorry! Chief cook is not appeared!" << endl; //
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement