/
githubmirror
/
CPlusPlusThings
Обзор
Документация
Войти
/
githubmirror
/
CPlusPlusThings
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
practical_exercises/10_day_practice/day9/exception/10.cpp
43 строки
671 B
zhangxing
support bazel complie this project and format code.
30 мар 2024, 17:00
30 мар 2024, 17:00
3c8a3f2
Код
Авторство
О чём код?
// Eg10-11.cpp #include <iostream> using namespace std; const int MAX = 3; class Full { int a; public: Full(int i) : a(i) {} int getValue() { return a; } }; class Empty {}; class Stack { private: int s[MAX]; int top; public: Stack() { top = -1; } void push(int a) { if (top >= MAX - 1) throw Full(a); s[++top] = a; } int pop() { if (top < 0) throw Empty(); return s[top--]; } }; int main() { Stack s; try { s.push(10); s.push(20); s.push(30); s.push(40); } catch (Full e) { cout << "Exception: Stack Full..." << endl; cout << "The value not push in stack:" << e.getValue() << endl; } }