如何从显示板上将字符显示为字符串? [英] How to display character as a string from the displayboard?

查看:54
本文介绍了如何从显示板上将字符显示为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将字符显示为我在板上设置的字符串时遇到问题.我如何像字符串一样从板上显示我的字符.例如,当我输入 AABBA 时,输出将使用我在板上为 A 和 B 设置的设计将 AABBA 显示为字符串.

I am having problems in displaying the character as a string which I have set on my board. How do i display out my character from the board like a string.For example, when I input AABBA , the output will show AABBA as a string using the design i have set on my board for A and B.

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring> 

using namespace std ;

void display(int dimI , int dimJ, const char A[20][40])
{
    for (int i =0 ; i < dimI ; ++i)
    {
        for (int j = 0 ; j < dimJ ; ++j)
        {
            cout << A[i][j];
        }
        cout << endl ;
    }
}
void clearScreen();
void delay() ;

int main()
{

    const int dimI = 20, dimJ = 40;
    string letter ;
    string displayboard(int dimI , int dimJ, const char A[20][40]) ;

    cout << "Please enter a word or number:";   
    getline(cin, letter);


    for(int i=0; i<letter.length(); ++i)
    {

    switch(letter[i])                          
    {

    case 'A' :
    {

    char board_A[dimI][dimJ] =
       {
             {' ' , ' ' , '#' , ' ' , ' ' },
             {' ' , '#' , ' ' , '#' , ' ' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , '#' , '#' , '#' , '#' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , ' ' , ' ' ,' '  , '#' }
        };

    display(dimI,dimJ,board_A);
    break ;
    }

     case 'B'  :
    {

     char board_B[dimI][dimJ] =
       {
             {'#' , '#' , '#' , '#' , ' ' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , '#' , '#' , '#' , ' ' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , ' ' , ' ' , ' ' , '#' },
             {'#' , '#' , '#' ,'#'  , ' ' }
       };
       display(dimI,dimJ,board_B);
       break ;
    }

void display( string displayboard [20][40] ,int dimI , int dimJ )
{

    for (int i =0 ; i< dimI ; ++i)
    {
        for (int j = 0 ; j, dimJ ; ++j)
        {
            cout << displayboard[i][j];
        }

        cout << endl ;
    }
    delay();
    clearScreen();
}

void delay()  
{
    for (int i = 0 ; i < 1000000000 ; ++i) ;
}

void clearScreen() 
{
    system("cls");
}

我希望输出是 AABBA 作为字符串并水平显示.当我运行我的程序时,它只将它显示为一个单独的字母而不是字符并排的字符串.除此之外,我也在考虑做一个循环,让角色能够上下、从左到右滚动,让它看起来像一个环绕效果.

I expect the output to be AABBA as a string and display it horizontally.When i run my program,it only display it as an individual letter instead of a string whereby the characters are side by side. Other than that, I am also thinking about making a loop so that the characters are able to scroll upwards and downwards,and left to right,making it look like a wrap around effect.

推荐答案

根据@Yunnosch 先生的回答,您必须实现如下所示的代码.

as per @Yunnosch sir's answer you have to implement code may like below.

在此处显示

您的展示方法:

void display(string letter)
{
  const int dimI = 20, dimJ = 40;
  char board_A[dimI][dimJ] =
                   {
                         {' ' , ' ' , '#' , ' ' , ' ' },
                         {' ' , '#' , ' ' , '#' , ' ' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , '#' , '#' , '#' , '#' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , ' ' , ' ' ,' '  , '#' }
                    };

char board_B[dimI][dimJ] =
                   {
                         {'#' , '#' , '#' , '#' , ' ' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , '#' , '#' , '#' , ' ' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , ' ' , ' ' , ' ' , '#' },
                         {'#' , '#' , '#' ,'#'  , ' ' }
                   };
                  for (int i =0 ; i< dimI ; ++i)
                  {                       
                        for(int k=0; k<letter.length(); ++k)
                        {

                              switch(letter[k])                          
                                {
                                    case 'A' :
                                            { 
                                              cout<<board_A[i];              
                                              break;
                                            }   

                                    case 'B'  :                    
                                            {
                                              cout<<board_B[i]; 
                                              break;
                                            }
                                }                                  


                      }
                      cout<<endl;
                  }

 }

这篇关于如何从显示板上将字符显示为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆