Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <clocale>
- #include <windows.h>
- using namespace std;
- //Написати програму, яка створює бінарний файл з даними про сканери (дані вводяться з
- //клавіатури) – 6 - 8 записів.Передбачити також виводити вмісту файла на екран.
- //Написати функцію, яка виводить дані з файлу, що відповідають умовам, зазначеним у варіанті
- //завдання :
- //Підрахувати кількість сканерів дорожчих за 1000 грн.
- struct scan_info {
- char model[25]; // найменування моделі
- int price; // ціна
- double x_size; // горизонтальний розмір області сканування
- double y_size; // вертикальний розмір області сканування
- int optr; // оптичний дозвіл
- int grey; // число градацій сірого
- };
- int IntInput()
- {
- int imputNumber;
- while (!(cin >> imputNumber) || (cin.peek() != '\n'))
- {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Это не целое число. Попробуйте еще раз.\n";
- }
- return imputNumber;
- }
- double DoubleInput()
- {
- double imputNumber;
- while (!(cin >> imputNumber) || (cin.peek() != '\n'))
- {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Это не число. Попробуйте еще раз.\n";
- }
- return imputNumber;
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- ofstream Fout;
- Fout.open("C:\\Users\\User\\Desktop\\OutputScaners.scaners", ios::binary);
- int scanersCount;
- cout << "Введите количество сканеров:";
- scanersCount = IntInput();
- scan_info TScanerOutput;
- for (int i = 1; i <= scanersCount; i++)
- {
- cout << "----- Сканер #" << i << " -----";
- cout << "\nВведите название модели:";
- cin >> TScanerOutput.model;
- cout << "\nВведите цену модели:";
- TScanerOutput.price = IntInput();
- cout << "\nВведите горизонтальный размер области сканирования:";
- TScanerOutput.x_size = DoubleInput();
- cout << "\nВведите вертикальный размер области сканирования:";
- TScanerOutput.y_size = DoubleInput();
- cout << "\nВведите оптическое разрешение:";
- TScanerOutput.optr = IntInput();
- cout << "\nВведите число градаций серого:";
- TScanerOutput.grey = IntInput();
- system("cls");
- Fout.write((char*)&TScanerOutput, sizeof(TScanerOutput));
- }
- cout << "Вывести данные файла на экран?(ДА - Space. НЕТ - Esc)";
- while (true)
- {
- if (GetAsyncKeyState(VK_SPACE))
- {
- ifstream Fin;
- scan_info TScanerInput;
- //TScanerInput = new scan_info[scanersCount];
- Fin.open("C:\\Users\\User\\Desktop\\OutputScaners.scaners", ios::binary);
- int moreThanThousand = 0;
- while (!Fin.eof()) //Фиксить чтение структруры
- {
- Fin.read((char*)&TScanerInput, sizeof(scan_info));
- //for (int i = 0; i < scanersCount; i++)
- //{
- cout << endl << TScanerInput/*[i]*/.model;
- cout << endl << TScanerInput/*[i]*/.price;
- cout << endl << TScanerInput/*[i]*/.x_size;
- cout << endl << TScanerInput/*[i]*/.y_size;
- cout << endl << TScanerInput/*[i]*/.optr;
- cout << endl << TScanerInput/*[i]*/.grey;
- //}
- //if (Fin.read((char*)&TScanerInput, sizeof(TScanerInput)))
- //{
- // if (TScanerInput.price > 1000)
- // {
- // moreThanThousand++;
- // }
- //}
- }
- Fin.close();
- cout << endl << "Сканеров дороже 1000: " << moreThanThousand << " шт.";
- break;
- }
- if (GetAsyncKeyState(VK_ESCAPE))
- {
- break;
- }
- }
- Fout.close();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment