Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //console.h
- #include <iostream>
- class Keyboard {
- public:
- Keyboard() { std::cout << "Keyboard input initialized\n";}
- virtual ~Keyboard() { std::cout << "Keyboard input uninitialized\n";}
- void inputInstruction();
- protected:
- std::string currentInstruction;
- };
- class Screen {
- public:
- Screen() {std::cout << "Screen output initilized\n";}
- virtual ~Screen() {std::cout << "Screen output unitialized\n"; }
- void output(std::string outputLine);
- void setBackgroundColor(std::string color);
- protected:
- std::string backgroundColor;
- };
- class Console : public Screen, public Keyboard {
- public:
- Console();
- virtual ~Console() { }
- void executeInstruction();
- protected:
- private:
- };
- //console.cpp
- #include "console.h"
- Console::Console() :
- Screen(), Keyboard() {
- std::cout << "Instructions:\n-setBackgroundColor <color>\n-shutdown\n"
- << "---------------------------\n> ";
- }
- void Keyboard::inputInstruction() {
- std::cin >> currentInstruction;
- }
- void Screen::output(std::string outputLine) {
- std::cout << outputLine;
- }
- void Screen::setBackgroundColor(std::string color) {
- output("Switched background color to " + color + "\n");
- }
- void Console::executeInstruction() {
- do {
- inputInstruction();
- if(currentInstruction == "setBackgroundColor") {
- std::cin >> currentInstruction;
- setBackgroundColor(currentInstruction);
- }
- output("> ");
- } while(currentInstruction != "shutdown");
- }
- //main.cpp
- #include <iostream>
- #include "console.h"
- int main() {
- Console *console = new Console();
- console->executeInstruction();
- delete console;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement