Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- template <typename Type>
- Type MagicInput(Type input) // Ввод с проверкой
- {
- while (!(cin >> input) || (cin.peek() != '\n'))
- {
- cin.clear(); while (cin.get() != '\n');
- cout << "Ошибка ввода. Попробуйте еще раз.\n";
- }
- return input;
- }
- void SetLucidaFont()
- {
- HANDLE hCon = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- if (hCon != INVALID_HANDLE_VALUE) {
- CONSOLE_FONT_INFOEX cfi;
- cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
- cfi.nFont = 0;
- cfi.dwFontSize.X = 0;
- cfi.dwFontSize.Y = 12;
- cfi.FontFamily = FF_DONTCARE;
- cfi.FontWeight = 400;
- wcscpy_s(cfi.FaceName, L"Lucida Console");
- SetCurrentConsoleFontEx(hCon, FALSE, &cfi);
- }
- }
- template<typename Type>
- void quickSort(Type* arr, int left, int right) {
- Type tmp, pivot = arr[(left + right) / 2];
- int i = left, j = right;
- while (i <= j) {
- while (arr[i] < pivot) i++;
- while (arr[j] > pivot) j--;
- if (i <= j) {
- tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp;
- i++; j--;
- }
- }
- if (left < j) quickSort(arr, left, j);
- if (i < right) quickSort(arr, i, right);
- }
- template <typename Type>
- class Array
- {
- private:
- Type* array;
- int size;
- public:
- Array(int sizeIn = 10)
- {
- size = sizeIn > 0 ? sizeIn : 10;
- array = new Type[size];
- for (int i = 0; i < size; i++) array[i] = 0;
- }
- void InputArray();
- Type FindMin();
- void ArrayOutput();
- void ArraySort() { quickSort(array, 0, size - 1); }
- };
- template <typename Type>
- void Array<Type>::InputArray()
- {
- system("cls");
- for (int i = 0; i < size; i++)
- {
- cout << "Введите " << i + 1 << " эллемент массива: ";
- array[i] = MagicInput((Type)0);
- }
- }
- template <typename Type>
- Type Array<Type>::FindMin()
- {
- Type min = array[0];
- for (int i = 0; i < size; i++)
- if (min > array[i])
- min = array[i];
- cout << endl << "Минимум: " << min << endl;
- system("pause");
- return min;
- }
- template <typename Type>
- void Array<Type>::ArrayOutput()
- {
- cout << endl;
- for (int i = 0; i < size; i++)
- cout << array[i] << " ";
- cout << endl; system("pause");
- }
- void Menu()
- {
- system("cls");
- cout << "---Выберите опцию: ";
- cout << endl << "--------------Int--------------";
- cout << endl << "1. Ввести все элементы массива";
- cout << endl << "2. Вывод минимального элемента";
- cout << endl << "3. Вывод элементов массива";
- cout << endl << "4. Сортировка массива";
- cout << endl << "-------------Double------------";
- cout << endl << "5. Ввести все элементы массива";
- cout << endl << "6. Вывод минимального элемента";
- cout << endl << "7. Вывод элементов массива";
- cout << endl << "8. Сортировка массива";
- cout << endl << "-------------------------------";
- cout << endl << "ESC. Выход";
- }
- int main()
- {
- system("mode con cols=80 lines=30");
- SetLucidaFont();
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- cout << "Введите размерность массива(Int): ";
- Array<int> arrayInt(MagicInput((int)0));
- cout << "Введите размерность массива(Double): ";
- Array<double> arrayDouble(MagicInput((int)0));
- while (true)
- {
- Menu();
- switch (_getch())
- {
- case 49/*-1-*/: arrayInt.InputArray(); break;
- case 50/*-2-*/: arrayInt.FindMin(); break;
- case 51/*-3-*/: arrayInt.ArrayOutput(); break;
- case 52/*-4-*/: arrayInt.ArraySort(); break;
- case 53/*-5-*/: arrayDouble.InputArray(); break;
- case 54/*-6-*/: arrayDouble.FindMin(); break;
- case 55/*-7-*/: arrayDouble.ArrayOutput(); break;
- case 56/*-8-*/: arrayDouble.ArraySort(); break;
- case 27/*ESC*/: return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment