Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- using namespace std;
- struct notebook {
- char model[20]; // найменування моделі
- int price; // ціна
- int disp_x; // роздільна здатність дисплея по горизонталі
- int disp_y; // роздільна здатність дисплея по вертикалі
- int f; // частота регенерації
- float d; // розмір діагоналі дисплея
- float weight; // вага
- };
- //-------------------------
- void SortInAscendingOrderSumOfMatrixColumns(int Matrix[100][100], int& line, int& column)
- {
- int sumInColunms[100];
- for (int i = 0; i < column; i = -~i) // i = -~i равнозначно i++
- {
- sumInColunms[i] = 0;
- for (int j = 0; j < line; j = -~j)
- {
- sumInColunms[i] += Matrix[i][j];
- }
- }
- QuickSort(sumInColunms, 0, column - 1, line, Matrix);
- }
- void QuickSort(int *Array, int nStart, int nEnd, int lines, int Matrix[100][100])
- {
- if (nStart >= nEnd)
- return; // готово
- int Left = nStart, Right = nEnd, X;
- X = Array[(Left + Right) / 2]; // или X = A[irand(L,R)];
- while (Left <= Right)
- { // разделение
- while (Array[Left] < X)
- {
- Left++;
- }
- while (Array[Right] > X)
- {
- Right--;
- }
- if (Left <= Right)
- {
- Array[Left] ^= Array[Right];
- Array[Right] ^= Array[Left];
- Array[Left] ^= Array[Right];
- for (int j = 0; j < lines; j = -~j)
- {
- Matrix[Left][j] ^= Matrix[Right][j];
- Matrix[Right][j] ^= Matrix[Left][j];
- Matrix[Left][j] ^= Matrix[Right][j];
- }
- Left++; Right--;
- }
- }
- QuickSort(Array, nStart, Right, lines, Matrix); // рекурсивные вызовы
- QuickSort(Array, Left, nEnd, lines, Matrix);
- }
- //Написати програму, яка зчитує дані про ноутбуки в динамічний масив наведеної структури.
- //Виконує обробку зчитаної інформації згідно варіанту та записує результати в бінарний файл
- //«note_out.dat».Структура бинарного файла «note_out.dat»: первые 4 байта – целое число записей в
- //файле; далее записи в формате структуры notebook.
- //Передбачити також виводити вмісту файла на екран.
- //Записати в бінарний файл дані тільки про ті ноутбуки, частота регенерації яких більша за 80
- //Гц, відсортованих за збільшенням ціни
- void main()
- {
- notebook *notebookArray;
- int noteboookCount = 0;
- ifstream Fin("C:\\Users\\User\\Desktop\\notebook.dat", ios::binary);
- notebook fileRead;
- while (!Fin.eof())
- {
- if (Fin.read((char*)&fileRead, sizeof(notebook)))
- {
- noteboookCount++;
- }
- }
- if (noteboookCount > 0)
- {
- notebookArray = new notebook[noteboookCount];
- Fin.close();
- Fin.open("C:\\Users\\User\\Desktop\\notebook.dat", ios::binary);
- Fin.read((char*)notebookArray, noteboookCount * sizeof(notebook));
- for (int i = 0; i < noteboookCount; i++)
- {
- cout << endl << i;
- cout << endl << notebookArray[i].model;
- cout << endl << notebookArray[i].price;
- cout << endl << notebookArray[i].disp_x;
- cout << endl << notebookArray[i].disp_y;
- cout << endl << notebookArray[i].f;
- cout << endl << notebookArray[i].d;
- cout << endl << notebookArray[i].weight;
- }
- delete[]notebookArray;
- }
- else
- {
- cout << "Данных в файле нет";
- }
- ofstream Fout("C:\\Users\\User\\Desktop\\note_out.dat", ios::binary);
- Fin.close();
- Fout.close();
- cout << endl << "Press Esc to close.";
- while (!GetAsyncKeyState(VK_ESCAPE))
- {
- }
- }
Add Comment
Please, Sign In to add comment