42Seoul/CPP Module 01

ex06

재윤 2023. 12. 2. 12:47
반응형

 

ex05에서 했던 함수 포인터 배열을 사용하는 것에서 switch문만 추가하면 된다.

 

Harl.cpp

#include "Harl.hpp"

Harl::Harl() {}

Harl::~Harl() {}

void	Harl::debug(void)
{
	std::cout << "[ DEBUG ]" << std::endl;
	std::cout << "I love to get extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger.\\nI just love it!\\n" << std::endl;
}

void	Harl::info(void)
{
	std::cout << "[ INFO ]" << std::endl;
	std::cout << "I cannot believe adding extra bacon cost more money.\\nYou don’t put enough! If you did I would not have to ask for it!\\n" << std::endl;
}

void	Harl::warning(void)
{
	std::cout << "[ WARNING ]" << std::endl;
	std::cout << "I think I deserve to have some extra bacon for free.\\nI’ve been coming here for years and you just started working here last month.\\n" << std::endl;
}

void	Harl::error(void)
{
	std::cout << "[ ERROR ]" << std::endl;
	std::cout << "This is unacceptable, I want to speak to the manager now." << std::endl;
}

void Harl::complain(std::string level) 
{
	std::string types[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};

	int i;
	for (i = 0; i < 4; i++)
	{
		if (types[i] == level) 
		   	break ;
	}
	switch (i)
	{
		case 0:
			this->debug();
		case 1:
			this->info();
		case 2:
			this->warning();
		case 3:
			this->error();
			break ;
			
		default:
			std::cout << "[ Probably complaining about insignificant problems ]" << std::endl;
	}
}
반응형

'42Seoul > CPP Module 01' 카테고리의 다른 글

ex05(함수 포인터 배열)  (0) 2023.12.02
ex04  (0) 2023.12.01
ex03  (0) 2023.12.01
ex02  (0) 2023.12.01
ex01(객체 포인터 배열 할당)  (0) 2023.12.01