Advertisement
vladkomarr

Untitled

Nov 27th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. //console.h
  2. #include <iostream>
  3.  
  4. class Keyboard {
  5. public:
  6.     Keyboard() { std::cout << "Keyboard input initialized\n";}
  7.     virtual ~Keyboard() { std::cout << "Keyboard input uninitialized\n";}
  8.     void inputInstruction();
  9. protected:
  10.     std::string currentInstruction;
  11. };
  12.  
  13. class Screen {
  14. public:
  15.     Screen() {std::cout << "Screen output initilized\n";}
  16.     virtual ~Screen() {std::cout << "Screen output unitialized\n"; }
  17.     void output(std::string outputLine);
  18.     void setBackgroundColor(std::string color);
  19. protected:
  20.     std::string backgroundColor;
  21. };
  22.  
  23. class Console : public Screen, public Keyboard {
  24. public:
  25.     Console();
  26.     virtual ~Console() { }
  27.     void executeInstruction();
  28. protected:
  29. private:
  30. };
  31.  
  32. //console.cpp
  33.  
  34. #include "console.h"
  35.  
  36. Console::Console() :
  37.     Screen(), Keyboard() {
  38.     std::cout << "Instructions:\n-setBackgroundColor <color>\n-shutdown\n"
  39.               << "---------------------------\n> ";
  40. }
  41.  
  42. void Keyboard::inputInstruction() {
  43.     std::cin >> currentInstruction;
  44. }
  45.  
  46. void Screen::output(std::string outputLine) {
  47.     std::cout << outputLine;
  48. }
  49.  
  50. void Screen::setBackgroundColor(std::string color) {
  51.     output("Switched background color to " + color + "\n");
  52. }
  53.  
  54. void Console::executeInstruction() {
  55.     do {
  56.         inputInstruction();
  57.         if(currentInstruction == "setBackgroundColor") {
  58.             std::cin >> currentInstruction;
  59.             setBackgroundColor(currentInstruction);
  60.         }
  61.         output("> ");
  62.     } while(currentInstruction != "shutdown");
  63. }
  64.  
  65. //main.cpp
  66. #include <iostream>
  67. #include "console.h"
  68.  
  69. int main() {
  70.     Console *console = new Console();
  71.     console->executeInstruction();
  72.     delete console;
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement