Vla_DOS

Untitled

Sep 22nd, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>  // SetConsoleCP, SetConsoleOutputCP
  3. #include <locale.h>
  4. #include <conio.h>
  5. #include <algorithm>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9. #define і i
  10.  
  11. class Customer {
  12. private:
  13.     int id, creditCardNumber;
  14.     string lastName, firstName, surName, address, bankAccountNumber;
  15.  
  16. public:
  17.     Customer() {}
  18.  
  19.     Customer(int id, string firstName, string lastName, string surName, string address, int creditCardNumber, string bankAccountNumber) {
  20.         this->id = id;
  21.         this->firstName = firstName;
  22.         this->lastName = lastName;
  23.         this->surName = surName;
  24.         this->address = address;
  25.         this->creditCardNumber = creditCardNumber;
  26.         this->bankAccountNumber = bankAccountNumber;
  27.     }
  28.  
  29.     static void AddItemArray(Customer* customers, int size)
  30.     {
  31.         int id, creditCardNumber;
  32.         string lastName, firstName, surName, address, bankAccountNumber;
  33.         for (int i = 0; i < size; i++)
  34.         {
  35.             cout << "Id: ";
  36.             cin >> id;
  37.  
  38.             cout << "Ім’я: ";
  39.             cin >> firstName;
  40.  
  41.             cout << "Прізвище: ";
  42.             cin >> lastName;
  43.  
  44.             cout << "По батькові: ";
  45.             cin >> surName;
  46.  
  47.             cout << "Адреса: ";
  48.             cin >> address;
  49.  
  50.             cout << "Номер кредитної картки: ";
  51.             cin >> creditCardNumber;
  52.  
  53.             cout << "Номер банківського рахунку: ";
  54.             cin >> bankAccountNumber;
  55.  
  56.             customers[i] = Customer(id, firstName, lastName, surName, address, creditCardNumber, bankAccountNumber);
  57.         }
  58.     }
  59.  
  60.     static void GetArray(Customer* customers, int size) {
  61.  
  62.         for (int i = 0; i < size; i++)
  63.         {
  64.             cout << "Id - " << customers[i].id << ". Ім’я - " << customers[i].firstName << ". Прізвище - " << customers[i].lastName << ". По батькові - " << customers[i].surName << ". Адреса - " << customers[i].address << ". Номер кредитної картки - " << customers[i].creditCardNumber << ". Номер банківського рахунку - " << customers[i].bankAccountNumber << endl;
  65.         }
  66.  
  67.  
  68.     }
  69.  
  70.     void Sort(Customer* customers, int size)
  71.     {
  72.         for (int i = 0; i < size; i++)
  73.         {
  74.             for (int j = 0; j < size - 1; j++)
  75.             {
  76.                 if (customers[j].firstName < customers[j + 1].firstName)
  77.                 {
  78.                     auto b = customers[j];
  79.                     customers[j] = customers[j + 1];
  80.                     customers[j + 1] = b;
  81.                 }
  82.             }
  83.         }
  84.     }
  85.  
  86.     void ListCreditCardNumber(Customer* customers, int size, int min, int max) {
  87.         for (int i = 0; i < size; i++)
  88.         {
  89.             if (customers[i].creditCardNumber >= min && customers[i].creditCardNumber <= max)
  90.                 cout << "Id - " << customers[i].id << ". Ім’я - " << customers[i].firstName << ". Прізвище - " << customers[i].lastName << ". По батькові - " << customers[i].surName << ". Адреса - " << customers[i].address << ". Номер кредитної картки - " << customers[i].creditCardNumber << ". Номер банківського рахунку - " << customers[i].bankAccountNumber << endl;
  91.         }
  92.     }
  93.  
  94.     void ListBankAccountNumber(Customer* customers, int size, char number) {
  95.         for (int i = 0; i < size; i++)
  96.         {
  97.             if (customers[i].bankAccountNumber[customers[i].bankAccountNumber.size() - 1] == number)
  98.                 cout << "Id - " << customers[i].id << ". Ім’я - " << customers[i].firstName << ". Прізвище - " << customers[i].lastName << ". По батькові - " << customers[i].surName << ". Адреса - " << customers[i].address << ". Номер кредитної картки - " << customers[i].creditCardNumber << ". Номер банківського рахунку - " << customers[i].bankAccountNumber << endl;
  99.         }
  100.     }
  101.  
  102.     void fileWrite(const char* txt, Customer* customers, int kol) {
  103.         ofstream t(txt, ios::binary | ios::app);
  104.         for (int i = 0; i < kol; i++) {
  105.             t.write((char*)&customers[i], sizeof customers[i]);
  106.         }
  107.         t.close();
  108.     }
  109.  
  110.     void readFile(const char* txt, Customer* customers, int kol) {
  111.         ifstream t(txt, ios::binary);
  112.         for (int i = 0; i < kol; i++) {
  113.             t.read((char*)&customers[i], sizeof customers[i]);
  114.         }
  115.         t.close();
  116.     }
  117. };
  118.  
  119. int main() {
  120.     SetConsoleCP(1251);
  121.     SetConsoleOutputCP(1251);
  122.     const char* path = "file.bin";
  123.     const int size = 2;
  124.     Customer* c = new Customer[size];
  125.  
  126.  
  127.     c->AddItemArray(c, size);
  128.  
  129.     c->GetArray(c, size);
  130.     c->fileWrite(path, c, size);
  131.     c->readFile(path, c, size);
  132.  
  133.     c->Sort(c, size);
  134.     cout << endl;
  135.     c->GetArray(c, size);
  136.  
  137.     char number;
  138.     cout << "\nВведіть останню цифру банківського рахунку: ";
  139.     cin >> number;
  140.  
  141.     c->ListBankAccountNumber(c, size, number);
  142.  
  143.     int min, max;
  144.  
  145.     cout << "\nmin: ";
  146.     cin >> min;
  147.     cout << "max: ";
  148.     cin >> max;
  149.  
  150.     c->ListCreditCardNumber(c, size, min, max);
  151.     return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment