/
AirLexa
/
04
Обзор
Документация
Войти
/
AirLexa
/
04
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lesson_03/Task_1/Task_1.cpp
51 строка
1 KB
AirLexa
update: Task_1.cpp
26 фев 2026, 20:54
Верифицирован
26 фев 2026, 20:54
a010474
Код
Авторство
О чём код?
#include <iostream> #include <windows.h> class smart_array { private: int idx = 0; int len = 0; int* dim = nullptr; public: smart_array(int size) { idx = 0; len = size; dim = new int[len](); } ~smart_array() { delete[] dim; } void add_element(int el) { if (idx >= len) throw std::exception("Массив полон, больше нет места!"); dim[idx++] = el; } int get_element(int n) { if (n < 0) throw std::exception("Индекс массива меньше нуля!"); if (n >= idx) throw std::exception("Превышен мах индекс массива!"); return dim[n]; } }; int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); try { smart_array arr(5); arr.add_element(1); arr.add_element(4); arr.add_element(155); arr.add_element(14); arr.add_element(15); std::cout << arr.get_element(1) << std::endl; } catch (const std::exception& ex) { std::cout << ex.what() << std::endl; } return 0; }