Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LETI.INF.5.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "iostream"
- #include "fstream"
- #include <string>
- using namespace std;
- char* path_output = "output.txt";
- char* path_input1 = "input.txt";
- const int SIZE = 30;
- int realSIZE = 0;
- int* pA;
- bool solution()
- {
- cout << "OK? [y/n]";
- char result;
- do
- {
- cin >> result;
- } while (result != 'y' && result != 'n');
- return result == 'y' ? true : false;
- }
- bool fillArray()
- {
- int N, x;
- int size = SIZE;
- ifstream file_input(path_input1);
- if (file_input.is_open())
- {
- file_input >> N;
- if (N < 0)
- {
- cout << "ОШИБКА : " << "кол-во ожидаемых элементов отрицательно [" << N << "]" << "\n";
- cout << "Преобразовать кол-во элементов по модулю?" << "\n";
- if (solution())
- {
- N = abs(N);
- }
- else
- {
- cout << "Кол-во элементов сброшено до 0" << "\n";
- }
- }
- if (size < N)
- {
- cout << "ОШИБКА : " << "размер массива [" << size << "] меньше кол-ва ожидаемых элементов [" << N << "]" << "\n";
- cout << "Уменьшить кол-во ожидаемых элементов до [" << size << "]" << "\n";
- if (solution())
- {
- N = size;
- }
- else
- {
- return false;
- }
- }
- pA = new int[N];
- for (int j = 0; j < N; j++)
- {
- *(pA + j) = 0;
- }
- int counter = 0;
- cout << "Массив " << ":" << "\n";
- while (true)
- {
- if (file_input.eof())
- break;
- file_input >> x;
- *(pA + counter) = x;
- cout << *(pA + counter) << ' ';
- counter++;
- if (counter >= N)
- break;
- }
- cout << "\n";
- if (counter != N)
- {
- cout << "ВНИМАНИЕ : " << "кол-во загруженных элементов [" << counter << "] массива не соответствует кол-ву ожидаемых элементов [" << N << "]" << "\n";
- }
- realSIZE = counter;
- file_input.close();
- return true;
- }
- else
- {
- cout << "Unable to open file";
- return false;
- }
- }
- void main()
- {
- setlocale(LC_CTYPE, "Russian");
- cout << "Формирование нового упорядоченного массива из двух сущесвующих," << "\n" <<
- "содержащих упорядоченные множества, с помощью оперции объединения" << "\n" <<
- "при помощи динамических массивов" << "\n" <<
- "Автор : Визгунов Андрей Дмитриевич ФКТИ 7302" << "\n" <<
- "Версия : 20.a.1" << "\n" << "\n";
- fillArray();
- ofstream myfile(path_output);
- if (myfile.is_open())
- {
- cout << "Контрольный вывод:" << "\n" <<
- "Обработано [" << realSIZE << "] элементов для первого массива" << "\n" << "\n";
- myfile << "Контрольный вывод:" << "\n" <<
- "Обработано [" << realSIZE << "] элементов для первого массива" << "\n" << "\n";
- for (int i = 0; i < realSIZE / 2; ++i)
- {
- int temp = *(pA + i);
- *(pA + i) = *(pA + realSIZE - i - 1);
- *(pA + realSIZE - i - 1) = temp;
- if (i % ((realSIZE / 2) / 5) == 0) {
- myfile << "Промежуточные значения для [" << i << "] итерации :" << "\n";
- for (int i = 0; i < realSIZE; i++) {
- myfile << *(pA + i) << ' ';
- }
- myfile << "\n";
- }
- }
- myfile << "\n" << "Результаты:" << "\n";
- for (int i = 0; i < realSIZE; i++) {
- myfile << *(pA + i) << ' ';
- }
- myfile.close();
- }
- else cout << "Unable to open file";
- if (pA != nullptr)
- delete[]pA;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement