#include <iostream>
#include <cmath>  // for std::abs
#include <string>

const int PLANE_WIDTH = 11;
const int PLANE_HEIGHT = 10;

const int command_quit = 100;
const int command_fill = 200;
const int command_clear = 300;

void point( int x1, int y1, char plane[PLANE_HEIGHT][PLANE_WIDTH] );
void tessellate( int x1, int y1, int x2, int y2, char plane[PLANE_HEIGHT][PLANE_WIDTH] );
void display( char plane[PLANE_HEIGHT][PLANE_WIDTH] );

void get_user_input( int params[] );
void dispatch_command( int params[] );

int main()
{
    // Array to hold command code and command parameters:
    int cmd[5] = {0};
    for(;;) {
        get_user_input( cmd );
        if ( cmd[0] == command_quit )
            return 0;
        dispatch_command( cmd );
    }
}

// Input command from the user:
void get_user_input( int params[] )
{
    std::string command;
    std::cout << "\nEnter your command> ";
    std::cin >> command;

    if ( command == "quit" ) {
        params[0] = command_quit;

    } else if ( command == "fill" ) {
        params[0] = command_fill;
        char char_fill;
        std::cin >> char_fill;
        params[1] = char_fill;

    } else if ( command == "?" || command == "help" ) {
        std::cout
            << "The following commands are available:\n\n"
            << "    to draw a segment: segment x1 y1 x2 y2\n"
            << "      to draw a point: point x1 y1\n"
            << "     to clear drawing: clear\n"
            << "to fill drawing plane: fill C\n"
            << "              to quit: quit\n\n"
            << "Here, x1, y1, x2, and y2 are coordinates within\n"
            << "the following ranges X: from zero to " << PLANE_WIDTH - 1
            << ", and Y: from zero to " << PLANE_HEIGHT
            <<".\n"
            << "And C is a character to fill the blanks with.\n"
            << "\n"
            ;
    }
}

// Execute the action corresponding to the drawing command and
// display the result:
void dispatch_command( int params[] )
{
    // Array to store the drawing in memory:
    static char plane[PLANE_HEIGHT][PLANE_WIDTH] = {
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' },
        { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\n' }
    };

    // For each command, do what's necessary:
    if ( params[0] == command_fill ) {
        for ( int yy = 0; yy < PLANE_HEIGHT; ++yy )
            for ( int xx = 0; xx < PLANE_WIDTH; ++xx )
                if ( plane[yy][xx] == ' ' )
                    plane[yy][xx] = params[ 1 ];

    } else if ( params[0] == command_clear ) {
        // Fill the entire plane with blanks
        // ...
    }

    // Finally, display the drawing:
    display( plane );
}

// Print content of the plane array
void display( char plane[PLANE_HEIGHT][PLANE_WIDTH] )
{
    for ( int yy = 0; yy < PLANE_HEIGHT; ++yy )
        for ( int xx = 0; xx < PLANE_WIDTH; ++xx )
            std::cout << plane[yy][xx];
}