CARVIEW |
Select Language
HTTP/2 200
date: Sun, 12 Oct 2025 04:23:14 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=f66b81738941698fdd861e033846220b5abeee7193dc81f6e80d606fc1c2ab6ba%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22UMNrC-5x_o9G_1qX7WIXzfCH9SRUrLeB%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d3d21c3b63c151-BLR
#include <iostream>#include <fstream>#include <cmath>#include <string> - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- #include <string>
- using namespace std;
- void taskEssence() {
- setlocale(LC_ALL, "Rus");
- cout << "Данная программа находит количество строк квадратной матрицы, сумма модулей элементов которых больше 1." << endl;
- }
- string pathChoice() {
- string path;
- bool isNotCorrect;
- do {
- isNotCorrect = false;
- cout << "Введите путь к файлу: ";
- cin >> path;
- ifstream fin(path);
- if (fin.is_open()) {
- if (path.substr(path.find_last_of(".") + 1) != "txt") {
- cout << "Пожалуйста, убедитесь, что файл имеет расширение .txt" << endl;
- isNotCorrect = true;
- }
- else {
- cout << "Файл открыт успешно" << endl;
- }
- }
- else {
- cout << "Ошибка открытия файла" << endl;
- isNotCorrect = true;
- }
- fin.close();
- } while (isNotCorrect);
- return path;
- }
- int exceptRead(int i, int j) {
- bool isNotCorrect;
- int number;
- do {
- isNotCorrect = false;
- cout << "Введите " << (i + 1) << "," << (j + 1) << " пункт матрицы." << endl;
- cin >> number;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Неверный ввод данных!" << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- } while (isNotCorrect);
- return number;
- }
- int sizeMatrixInput() {
- int size;
- bool isNotCorrect;
- const int min_size = 1, max_size = 10;
- do {
- isNotCorrect = false;
- cout << "Введите порядок квадратной матрицы от " << min_size << " до " << max_size << " : ";
- cin >> size;
- if (cin.fail() || size < min_size || size > max_size) {
- cout << "Некорректный ввод. Пожалуйста, введите положительное целое число." << endl;
- cin.clear();
- while (cin.get() != '\n');
- isNotCorrect = true;
- }
- } while (isNotCorrect);
- return size;
- }
- double** matrixReadFile(const string& path, int sizeI, int sizeJ) {
- ifstream fin(path);
- bool isNotCorrect;
- string line;
- double** matrix = new double* [sizeI]; // выделение памяти для матрицы
- for (int i = 0; i < sizeI; i++) {
- matrix[i] = new double[sizeJ];
- }
- cout << "Запись матрицы..." << endl;
- for (int i = 0; i < sizeI; i++) {
- for (int j = 0; j < sizeJ; j++) {
- do {
- isNotCorrect = false;
- fin >> matrix[i][j];
- if (fin.fail()) {
- isNotCorrect = true;
- cout << "Данные введены некорректно. Ошибка в " << (i + 1) << "," << (j + 1) << ". Исправьте ошибку и перезагрузите программу " << endl;
- fin.clear();
- while (fin.get() != '\n');
- matrix[i][j] = exceptRead(i, j);
- }
- } while (isNotCorrect);
- }
- }
- fin.close(); // закрыть файл после чтения
- return matrix;
- }
- double** matrixReadConsole(int size) {
- double** matrix = new double* [size];
- for (int i = 0; i < size; i++) {
- matrix[i] = new double[size];
- for (int j = 0; j < size; j++) {
- bool isNotCorrect;
- do {
- isNotCorrect = false;
- cout << "Введите элемент матрицы с индексом " << (i + 1) << "," << (j + 1) << ": ";
- cin >> matrix[i][j];
- if (cin.fail()) {
- cout << "Неверный ввод данных!" << endl;
- cin.clear();
- while (cin.get() != '\n');
- isNotCorrect = true;
- }
- } while (isNotCorrect);
- }
- }
- return matrix;
- }
- int countRowsWithSumGreaterThanOne(double** matrix, int size) {
- int count = 0;
- for (int i = 0; i < size; i++) {
- double sum = 0;
- for (int j = 0; j < size; j++) {
- sum += abs(matrix[i][j]);
- }
- if (sum > 1) {
- count++;
- }
- }
- return count;
- }
- void outputResult(int result) {
- cout << "Количество строк, сумма модулей элементов которых больше 1: " << result << endl;
- string path;
- bool isNotCorrect;
- do {
- isNotCorrect = false;
- cout << "Введите путь к файлу для вывода: ";
- cin >> path;
- ofstream fout(path, fstream::app);
- if (fout.is_open()) {
- cout << "Файл успешно открыт!" << endl;
- fout << "Количество строк, сумма модулей элементов которых больше 1: " << result << endl;
- }
- else {
- cout << "Ошибка открытия файла" << endl;
- isNotCorrect = true;
- }
- fout.close();
- cout << "Ответ записан в файл." << endl;
- } while (isNotCorrect);
- }
- int main() {
- double** matrix = nullptr;
- int size;
- int finalOutput;
- int choice;
- bool isNotCorrect;
- taskEssence();
- cout << "Выберите источник данных для матрицы:" << endl;
- do {
- isNotCorrect = false;
- cout << "Введите 0 для ввода с консоли, или 1 для ввода из файла: ";
- cin >> choice;
- if (cin.fail() || (choice != 0 && choice != 1)) {
- cout << "Некорректный ввод!" << endl;
- cin.clear();
- while (cin.get() != '\n');
- isNotCorrect = true;
- }
- } while (isNotCorrect);
- if (choice == 0) {
- size = sizeMatrixInput(); // запрашиваем размер матрицы перед вводом
- matrix = matrixReadConsole(size);
- }
- else {
- size = sizeMatrixInput(); // запрашиваем размер матрицы перед вводом
- string path = pathChoice();
- matrix = matrixReadFile(path, size, size);
- if (matrix == nullptr) {
- return 1;
- }
- }
- finalOutput = countRowsWithSumGreaterThanOne(matrix, size);
- outputResult(finalOutput);
- for (int i = 0; i < size; i++) {
- delete[] matrix[i];
- }
- delete[] matrix;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
✅⭐ Make huge profits on trading ⭐⭐ B
JavaScript | 1 sec ago | 0.25 KB
-
⭐✅ Marketplace Glitch ✅ Working ✅ NEVER SEEN...
JavaScript | 10 sec ago | 0.25 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ O
JavaScript | 20 sec ago | 0.25 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 7
JavaScript | 29 sec ago | 0.25 KB
-
⭐✅ Swapzone Glitch ✅ Working ⭐⭐ P
JavaScript | 39 sec ago | 0.25 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ E
JavaScript | 51 sec ago | 0.25 KB
-
📌 Swapzone +37% glitch ⭐ T
JavaScript | 1 min ago | 0.25 KB
-
✅⭐ Make huge profits on trading ⭐⭐ B
JavaScript | 1 min ago | 0.25 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand