带有数字的动态ASCII框

Raz*_*zna 4 c++

使用这组ASCII代码制作动态框时遇到问题。我真的不知道该怎么办。此动态框中也有数字。

我已经尝试在循环内部制作循环以调整盒子的大小。

int main(){
    char asciis[] = {'\xDA','\xB3','\xC3','\xC0','\x20','\xC4','\xC5','\xC1','\xBF','\xB4','\xD9', '\xC2'};
    int box size = (n*2)+1;
    char box[box size][box size]; //set the size of the box
    //set a in all coordinates
    /*for (int r = 0; r < n; r++){
        for (int c = 0; c < n; c++){
            box[r][c] = 'a';
        }
    }*/

    for (int r = 0; r < n; r++){
        for (int c = 0; c < n; c++){
            for (int boxrow = 0; boxrow < box size; boxrow++){
                for (int boxcol = 0; boxcol < box size; boxcol++){
                    //conditions
                }
            }
        }
        cout << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我要创建的输出: 在此处输入图片说明

https://i.imgur.com/YRgMlaJ.png

别介意这些数字,我只是在映射数组。

3Da*_*ave 5

我敢肯定有一个更简单的解决方案,但我的头上没有:

#include <iostream>

using namespace std;

enum  BoxParts {
    kLeftUpper = '\xDA',
    kVertical = '\xB3',
    kLeftBreak = '\xC3',
    kLeftLower = '\xC0',
    kEmpty = '\x20',
    kHorizontal = '\xC4',
    kIntersection = '\xC5',
    kBottomBreak = '\xC1',
    kRightUpper = '\xBF',
    kRightBreak = '\xB4',
    kRightLower = '\xD9',
    kTopBreak = '\xC2',
    kCount = 12
};

void drawLine(const int cellCount, const int cellWidth, const char left, const char divider, const char contents, const char right)
{
    cout << left;
    for (int i = 1; i < cellCount * cellWidth; ++i)
    {
        if (0 == i % cellWidth)
            cout << divider;
        else
            cout << contents;
    }
    cout << right << endl;
}

void drawBox(const int cellCount, const int cellWidth, const int cellHeight)
{
    // top
    drawLine(cellCount, cellWidth, kLeftUpper, kTopBreak, kHorizontal, kRightUpper);
    for (int i = 1; i < cellCount * cellHeight; ++i)
    {
        if (0 == i % cellHeight)
            drawLine(cellCount, cellWidth, kLeftBreak, kIntersection, kHorizontal, kRightBreak);
        else
            drawLine(cellCount, cellWidth, kVertical, kVertical, ' ', kVertical);
    }
    // bottom
    drawLine(cellCount, cellWidth, kLeftLower, kBottomBreak, kHorizontal, kRightLower);
}



int main(int argc, char** argv) {

    const int n = 4;
    drawBox(n, 10, 5);
    getchar();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

产生:

在此处输入图片说明