Created
January 25, 2024 15:12
-
-
Save kenpower/00296654f99b7b98975981c67546a2d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <memory> | |
#include <string> | |
// Abstract base class (interface) | |
class Chatbot { | |
public: | |
virtual void hello() = 0; | |
virtual void goodbye() = 0; | |
}; | |
// English implementation | |
class EnglishChatbot : public Chatbot { | |
public: | |
void hello() override { | |
std::cout << "Hello!" << std::endl; | |
} | |
void goodbye() override { | |
std::cout << "Goodbye!" << std::endl; | |
} | |
}; | |
// French implementation | |
class FrenchChatbot : public Chatbot { | |
public: | |
void hello() override { | |
std::cout << "Bonjour!" << std::endl; | |
} | |
void goodbye() override { | |
std::cout << "Au revoir!" << std::endl; | |
} | |
}; | |
// Spanish implementation | |
class SpanishChatbot : public Chatbot { | |
public: | |
void hello() override { | |
std::cout << "¡Hola!" << std::endl; | |
} | |
void goodbye() override { | |
std::cout << "¡Adiós!" << std::endl; | |
} | |
}; | |
int main() { | |
std::unique_ptr<Chatbot> chatbot; | |
std::string language; | |
std::cout << "Which language do you want? (English/French/Spanish): "; | |
std::cin >> language; | |
if (language == "English") { | |
chatbot = std::make_unique<EnglishChatbot>(); | |
} | |
else if (language == "French") { | |
chatbot = std::make_unique<FrenchChatbot>(); | |
} | |
else if (language == "Spanish") { | |
chatbot = std::make_unique<SpanishChatbot>(); | |
} | |
else { | |
std::cout << "Unknown language. Using English as default." << std::endl; | |
chatbot = std::make_unique<EnglishChatbot>(); | |
} | |
chatbot->hello(); | |
chatbot->goodbye(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment