Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //сериализовать по одному элементу
- #include<iostream>
- #include<fstream>
- #include<string>
- #include<vector>
- #include<algorithm>
- #include<iterator>
- #include <utility>
- #include <stdexcept>
- using namespace :: std;
- #pragma pack(push,1)
- struct PCRepair
- {
- string name;
- string surname;
- int age;
- string model;
- string status;
- struct Date_of_call
- {
- int day;
- int month;
- int year;
- }date_of_call;
- struct Deadline
- {
- int dday;
- int dmonth;
- int dyear;
- }deadline;
- };
- #pragma pack(pop)
- void vvod(vector<PCRepair> &z)
- {
- PCRepair fix;
- int choice =1;
- while(choice==1)
- {
- cout<<"Имя заказчика: ";
- cin>>fix.name;
- cout<<"Фамилия заказчика: ";
- cin>>fix.surname;
- cout<<"Возраст заказчика: ";
- cin>>fix.age;
- cout<<"Модель ноутбука: ";
- cin>>fix.model;
- cout<<"Статус выполнения(выполнен/выполняется): ";
- cin>>fix.status;
- cout<<"Дата поступления заказа, день: ";
- cin>>fix.date_of_call.day;
- cout<<"Месяц: ";
- cin>>fix.date_of_call.month;
- cout<<"Год: ";
- cin>>fix.date_of_call.year;
- cout<<"Дедлайн, день: ";
- cin>>fix.deadline.dday;
- cout<<"Месяц: ";
- cin>>fix.deadline.dmonth;
- cout<<"Год: ";
- cin>>fix.deadline.dyear;
- cout<<"Будете ещё вводить заказы? 1 -да, 0 - нет"<<endl;
- cin>>choice;
- z.push_back(fix);
- }
- }
- void output(vector<PCRepair> &z, int tmp)
- {
- cout<<"________________________________"<<endl;
- cout<<"| Имя: "<<z[tmp].name<<" |"<<endl;
- cout<<"| Фамилия: "<<z[tmp].surname<<" |"<<endl;
- cout<<"| Возраст: "<<z[tmp].age<<" Лет"<<" |"<<endl;
- cout<<"| Модель: "<<z[tmp].model<<" |"<<endl;
- cout<<"| Статус: "<<z[tmp].status<<" |"<<endl;
- cout<<"| Дата поступления: "<<z[tmp].date_of_call.day<<"."<<z[tmp].date_of_call.month<<"."<<z[tmp].date_of_call.year<<" |"<<endl;
- cout<<"| Дедлайн: "<<z[tmp].deadline.dday<<"."<<z[tmp].deadline.dmonth<<"."<<z[tmp].deadline.dyear<<" |"<<endl;
- cout<<"|________________________________|"<<endl;
- }
- int SEARCH_NAME(vector<PCRepair> &z)
- {
- PCRepair fix;
- int temp;
- cout<<"есть возможность найти 1.по ФИО"<<endl<<"2.по Модели ПК"<<endl;
- cin>>temp;
- switch(temp)
- {
- case 1:
- {
- int TETS;
- string namee, surnamee;
- cout<<"введите имя: ";
- cin>>namee;
- cout<<"введите фамилию: ";
- cin>>surnamee;
- for(int i=0; i<z.size(); i++)
- {
- if(z[i].name == namee && z[i].surname == surnamee)
- {
- output(z,i);
- TETS = i;
- return TETS;
- }
- }
- break;
- }
- case 2:
- {
- string mod;
- cout<<"введите модель: ";
- cin>>mod;
- int TETS;
- for(int i=0; i<z.size(); i++)
- {
- if(z[i].model == mod)
- {
- output(z,i);
- TETS = i;
- return TETS;
- }
- }
- break;
- }
- default:
- {
- cout<<"введено не верное число";
- return 0;
- break;
- }
- }
- }
- void change (vector<PCRepair> &z)
- {
- string tmp;
- int i;
- cout<<"найдите заказ который вам нужен."<<endl;
- i = SEARCH_NAME(z);
- cout<<"хотите ли вы изменить статус на противоположный? y/n"<<endl;
- cin>>tmp;
- if(tmp=="y"&&z[i].status=="выполняется")
- {
- z[i].status="выполнен";
- cout<<"изменения внесены, спасибо"<<endl;
- }
- if(tmp=="y"&&z[i].status=="выполнен")
- {
- z[i].status="выполняется";
- cout<<"изменения внесены, спасибо"<<endl;
- }
- else
- {
- cout<<"изменений не произошло."<<endl;
- }
- }
- void change (vector<PCRepair> &z)
- {
- string tmp;
- int i;
- cout<<"найдите заказ который вам нужен."<<endl;
- i = SEARCH_NAME(z);
- cout<<"хотите ли вы изменить статус на противоположный? y/n"<<endl;
- cin>>tmp;
- if(tmp=="y"&&z[i].status=="выполняется")
- {
- z[i].status="выполнен";
- cout<<"изменения внесены, спасибо"<<endl;
- }
- if(tmp=="y"&&z[i].status=="выполнен")
- {
- z[i].status="выполняется";
- cout<<"изменения внесены, спасибо"<<endl;
- }
- else
- {
- cout<<"изменений не произошло."<<endl;
- }
- }
- int main()
- {
- int point;
- vector<PCRepair> Bubuntu;
- PCRepair YEA;
- do
- {
- cout<<" **************1.ввод структур*****************"<<endl;
- cout<<" * ***************2.вывод структур************* *"<<endl;
- cout<<" * *************3.поиск элемента************* *"<<endl;
- cout<<" * *******4.сортировка по убыванию********* *"<<endl;
- cout<<" * ******5.сериализация вектора********** *"<<endl;
- cout<<" * *****6.десериализация вектора******** *"<<endl;
- cout<<" ************************7.выход***************************"<<endl;
- cin>>point;
- switch(point)
- {
- case 1:
- vvod(Bubuntu);
- break;
- case 2:
- {
- for(int i=0;i<Bubuntu.size();i++)
- {
- output(Bubuntu,i);
- }
- break;
- }
- case 3:
- {
- int temp;
- temp=SEARCH_NAME(Bubuntu);
- break;
- }
- case 4:
- output(Bubuntu, 0);
- break;
- case 5:
- {
- ofstream out("TEST.txt", std::ios_base::binary | std::ios_base::out);
- auto size = Bubuntu.size();
- out.write(reinterpret_cast<char*>(&size), sizeof(size));
- PCRepair* p = Bubuntu.data();
- out.write(reinterpret_cast<char*>(p), sizeof(PCRepair) * size);
- break;
- }
- case 6 :
- try {
- ifstream in{"TEST.txt", ios_base::binary};
- in.exceptions(in.exceptions() | ios_base::failbit);
- decltype(Bubuntu.size()) size{};
- in.read(reinterpret_cast<char*>(&size), sizeof(size));
- if (!size)
- throw runtime_error{"Coudn\'t read file!\n"}; // Необходимо #include <stdexcept>
- vector<PCRepair> v(size);
- auto ptrData = v.data();
- in.read(reinterpret_cast<char*>(ptrData), sizeof(PCRepair) * size);
- Bubuntu = std::move(v); // Необходимо #include <utility>
- break;
- }
- catch (exception const& e) {
- cerr << e.what() << endl;
- break;
- }
- default:
- cout<<"вы ввели некорректное число"<< endl;
- break;
- }
- }while(point!=7);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment