PhotoShaman

Зашквар12

Feb 17th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. struct notebook {
  8.     char model[20];         // найменування моделі
  9.     int price;              // ціна
  10.     int disp_x;             // роздільна здатність дисплея по горизонталі
  11.     int disp_y;             // роздільна здатність дисплея по вертикалі
  12.     int f;                  // частота регенерації
  13.     float d;                // розмір діагоналі дисплея
  14.     float weight;           // вага
  15. };
  16.  
  17. //-------------------------
  18.  
  19. void SortInAscendingOrderSumOfMatrixColumns(int Matrix[100][100], int& line, int& column)
  20. {
  21.     int sumInColunms[100];
  22.  
  23.     for (int i = 0; i < column; i = -~i) // i = -~i равнозначно i++
  24.     {
  25.         sumInColunms[i] = 0;
  26.         for (int j = 0; j < line; j = -~j)
  27.         {
  28.             sumInColunms[i] += Matrix[i][j];
  29.         }
  30.     }
  31.     QuickSort(sumInColunms, 0, column - 1, line, Matrix);
  32. }
  33.  
  34. void QuickSort(int *Array, int nStart, int nEnd, int lines, int Matrix[100][100])
  35. {
  36.     if (nStart >= nEnd)
  37.         return; // готово
  38.     int Left = nStart, Right = nEnd, X;
  39.  
  40.     X = Array[(Left + Right) / 2]; // или X = A[irand(L,R)];  
  41.  
  42.     while (Left <= Right)
  43.     { // разделение
  44.         while (Array[Left] < X)
  45.         {
  46.             Left++;
  47.         }
  48.         while (Array[Right] > X)
  49.         {
  50.             Right--;
  51.         }
  52.         if (Left <= Right)
  53.         {
  54.             Array[Left] ^= Array[Right];
  55.             Array[Right] ^= Array[Left];
  56.             Array[Left] ^= Array[Right];
  57.             for (int j = 0; j < lines; j = -~j)
  58.             {
  59.                 Matrix[Left][j] ^= Matrix[Right][j];
  60.                 Matrix[Right][j] ^= Matrix[Left][j];
  61.                 Matrix[Left][j] ^= Matrix[Right][j];
  62.             }
  63.             Left++; Right--;
  64.         }
  65.     }
  66.     QuickSort(Array, nStart, Right, lines, Matrix);   // рекурсивные вызовы
  67.     QuickSort(Array, Left, nEnd, lines, Matrix);
  68. }
  69.  
  70. //Написати програму, яка зчитує дані про ноутбуки в динамічний масив наведеної структури.
  71. //Виконує обробку зчитаної інформації згідно варіанту та записує результати в бінарний файл
  72. //«note_out.dat».Структура бинарного файла «note_out.dat»: первые 4 байта – целое число записей в
  73. //файле; далее записи в формате структуры notebook.
  74. //Передбачити також виводити вмісту файла на екран.
  75.  
  76. //Записати в бінарний файл дані тільки про ті ноутбуки, частота регенерації яких більша за 80
  77. //Гц, відсортованих за збільшенням ціни
  78. void main()
  79. {
  80.     notebook *notebookArray;
  81.     int noteboookCount = 0;
  82.  
  83.     ifstream Fin("C:\\Users\\User\\Desktop\\notebook.dat", ios::binary);
  84.     notebook fileRead;
  85.     while (!Fin.eof())
  86.     {
  87.         if (Fin.read((char*)&fileRead, sizeof(notebook)))
  88.         {
  89.             noteboookCount++;
  90.         }
  91.     }
  92.     if (noteboookCount > 0)
  93.     {
  94.         notebookArray = new notebook[noteboookCount];
  95.  
  96.         Fin.close();
  97.         Fin.open("C:\\Users\\User\\Desktop\\notebook.dat", ios::binary);
  98.         Fin.read((char*)notebookArray, noteboookCount * sizeof(notebook));
  99.  
  100.         for (int i = 0; i < noteboookCount; i++)
  101.         {
  102.             cout << endl << i;
  103.             cout << endl << notebookArray[i].model;
  104.             cout << endl << notebookArray[i].price;
  105.             cout << endl << notebookArray[i].disp_x;
  106.             cout << endl << notebookArray[i].disp_y;
  107.             cout << endl << notebookArray[i].f;
  108.             cout << endl << notebookArray[i].d;
  109.             cout << endl << notebookArray[i].weight;
  110.         }
  111.         delete[]notebookArray;
  112.     }
  113.     else
  114.     {
  115.         cout << "Данных в файле нет";
  116.     }
  117.  
  118.     ofstream Fout("C:\\Users\\User\\Desktop\\note_out.dat", ios::binary);
  119.     Fin.close();
  120.     Fout.close();
  121.     cout << endl << "Press Esc to close.";
  122.     while (!GetAsyncKeyState(VK_ESCAPE))
  123.     {
  124.    
  125.     }
  126. }
Add Comment
Please, Sign In to add comment