fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Device {
  5. public:
  6. std::string hostname;
  7. std::string enableSecret;
  8. std::string consolePassword;
  9. std::string motdBanner;
  10.  
  11. void setHostname(const std::string& name) {
  12. hostname = name;
  13. std::cout << "Hostname set to " << hostname << std::endl;
  14. }
  15.  
  16. void setEnableSecret(const std::string& secret) {
  17. enableSecret = secret;
  18. std::cout << "Enable secret set." << std::endl;
  19. }
  20.  
  21. void setConsolePassword(const std::string& password) {
  22. consolePassword = password;
  23. std::cout << "Console password set." << std::endl;
  24. }
  25.  
  26. void setMotdBanner(const std::string& banner) {
  27. motdBanner = banner;
  28. std::cout << "MOTD banner set: " << motdBanner << std::endl;
  29. }
  30.  
  31. void showConfiguration() {
  32. std::cout << "\nCurrent Configuration of " << hostname << ":\n";
  33. std::cout << "Enable Secret: " << (enableSecret.empty() ? "Not Set" : "Set") << std::endl;
  34. std::cout << "Console Password: " << (consolePassword.empty() ? "Not Set" : "Set") << std::endl;
  35. std::cout << "MOTD Banner: " << (motdBanner.empty() ? "Not Set" : motdBanner) << std::endl;
  36. }
  37. };
  38.  
  39. class Switch : public Device {
  40. public:
  41. void configureSwitch() {
  42. // Using sample values for the switch configuration
  43. setHostname("Switch1");
  44. setConsolePassword("cisco123");
  45. setEnableSecret("enableSecret123");
  46. setMotdBanner("# Welcome to Switch1 - Authorized Access Only! #");
  47. }
  48. };
  49.  
  50. class Router : public Device {
  51. public:
  52. void configureRouter() {
  53. // Using sample values for the router configuration
  54. setHostname("Router1");
  55. setConsolePassword("routerpass");
  56. setEnableSecret("routerEnableSecret");
  57. setMotdBanner("# Welcome to Router1 - Authorized Access Only! #");
  58. }
  59. };
  60.  
  61. int main() {
  62. Switch mySwitch;
  63. Router myRouter;
  64.  
  65. std::cout << "Configuring Switch...\n";
  66. mySwitch.configureSwitch();
  67. mySwitch.showConfiguration();
  68.  
  69. std::cout << "\nConfiguring Router...\n";
  70. myRouter.configureRouter();
  71. myRouter.showConfiguration();
  72.  
  73. return 0;
  74. }
  75.  
  76.  
  77.  
  78.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Configuring Switch...
Hostname set to Switch1
Console password set.
Enable secret set.
MOTD banner set: # Welcome to Switch1 - Authorized Access Only! #

Current Configuration of Switch1:
Enable Secret: Set
Console Password: Set
MOTD Banner: # Welcome to Switch1 - Authorized Access Only! #

Configuring Router...
Hostname set to Router1
Console password set.
Enable secret set.
MOTD banner set: # Welcome to Router1 - Authorized Access Only! #

Current Configuration of Router1:
Enable Secret: Set
Console Password: Set
MOTD Banner: # Welcome to Router1 - Authorized Access Only! #