/
rgd045
/
cpp-oop-basics
Обзор
Документация
Войти
/
rgd045
/
cpp-oop-basics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
projects/grades/main.cpp
44 строки
1 KB
OMP Education
Add modules
28 июн 2024, 01:09
28 июн 2024, 01:09
0ef3df8
Код
Авторство
О чём код?
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <edu@omp.ru> // SPDX-License-Identifier: BSD-3-Clause #include <iostream> class Exception { private: std::string m_message {"Not defined"}; public: Exception() {}; Exception(std::string message): m_message{message}{ }; void display() { std::cout << "Exception occurred: " << m_message << std::endl; } }; std::string gradeToText(int grade) { switch (grade) { case 1: return "poor"; case 2: return "unsatisfactory"; case 3: return "satisfactory"; case 4: return "good"; case 5: return "excellent"; default: throw Exception("wrong grade"); } } int main() { int grade; try{ grade = 1; std::cout << gradeToText(grade) << std::endl; grade = 3; std::cout << gradeToText(grade) << std::endl; grade = 10; std::cout << gradeToText(grade) << std::endl; } catch (Exception e) { e.display(); } return 0; }