Загрузка данных


#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <windows.h>
#include <cctype> // Для функций islower, isupper, tolower

using namespace std;

// Функция для генерации случайной буквы
char getRandomChar() {
    bool isUpper = rand() % 2;
    if (isUpper) return 'A' + rand() % 26;
    return 'a' + rand() % 26;
}

// Функция заполнения матрицы
void fillMatrix(vector<vector<char> >& mat) {
    for (size_t i = 0; i < mat.size(); i++) {
        for (size_t j = 0; j < mat[i].size(); j++) {
            mat[i][j] = getRandomChar();
        }
    }
}

// Функция вывода матрицы
void printMatrix(const vector<vector<char> >& mat) {
    cout << "\nТекущая матрица:\n";
    for (size_t i = 0; i < mat.size(); i++) {
        for (size_t j = 0; j < mat[i].size(); j++) {
            cout << setw(3) << mat[i][j];
        }
        cout << endl;
    }
}

// Проверка, является ли буква гласной
bool isVowel(char c) {
    c = tolower(c);
    return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
}

int main() {
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    srand(time(NULL));

    int n;
    cout << "Введите размер квадратной матрицы: ";
    cin >> n;

    vector<vector<char> > matrix(n, vector<char>(n));
    fillMatrix(matrix);

    int choice = -1;
    while (choice != 7) {
        system("cls");
        printMatrix(matrix);

        cout << "\n--- МЕНЮ ---" << endl;
        cout << "1 - Посчитать гласные" << endl;
        cout << "2 - Посчитать согласные" << endl;
        cout << "3 - Посчитать строчные (маленькие)" << endl;
        cout << "4 - Посчитать заглавные (большие)" << endl;
        cout << "5 - Перезаполнить текущую матрицу" << endl;
        cout << "6 - Изменить размер и перезаполнить" << endl;
        cout << "7 - Выход" << endl;
        cout << "\nВыберите действие: ";
        cin >> choice;

        if (choice == 7) break;

        int count = 0;
        switch (choice) {
            case 1: // Гласные
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        if (isalpha(matrix[i][j]) && isVowel(matrix[i][j])) count++;
                cout << "\nГласных букв: " << count << endl;
                break;

            case 2: // Согласные
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        if (isalpha(matrix[i][j]) && !isVowel(matrix[i][j])) count++;
                cout << "\nСогласных букв: " << count << endl;
                break;

            case 3: // Строчные
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        if (islower(matrix[i][j])) count++;
                cout << "\nСтрочных букв: " << count << endl;
                break;

            case 4: // Заглавные
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < n; j++)
                        if (isupper(matrix[i][j])) count++;
                cout << "\nЗаглавных букв: " << count << endl;
                break;

            case 5:
                fillMatrix(matrix);
                cout << "\nМатрица перезаполнена!" << endl;
                break;

            case 6:
                cout << "Введите новый размер: ";
                cin >> n;
                matrix.assign(n, vector<char>(n)); // Изменение размера
                fillMatrix(matrix);
                cout << "\nРазмер изменен, матрица перезаполнена!" << endl;
                break;

            default:
                cout << "\nНеверный пункт!" << endl;
        }

        cout << "\nНажмите любую клавишу...";
        system("pause > nul");
    }

    return 0;
}