Character pattern program -- Print large words using "X" characters

In summary: I found that std::vector was more powerful for this kind of task.IMO, generalization is the wrong way to go. The example letter, 'C', in the problem displays a large version of this letter in a 9 row by 5 column grid of 'X' characters and spaces. Instead of using a complicated if statement, I would use 9 x 5 two-D arrays consisting of 1s and 0s, one for each letter. Given an input character, I would have the program look up the appropriate array in the data section and then use a nested for loop to print 'X' wherever the array contains 1, and a space where there is a 0.
  • #1
shivajikobardan
674
54
I want to make a program that takes strings as input. eg: physicsforums. And writes that using x'es.
example c of physicsforums should look like this.
1686493243666.png

I've written the program for this.
Code:
#include <iostream>
using namespace std;
int main()
{
    int size;
    cout << "Enter the size of the pattern: ";
    cin >> size;

    for (int i = 0; i < size*2-1; i++)
    {
        for (int j = 0; j < size; j++)
        {
            if ((((i==0||i==2*size-2)&&j>1)||(i==1||i==2*size-3)&&(j==1||j==size-1))|| (j==0&&(i>1&&i<2*size-3)))
                cout << "X";
            else
                cout << " ";
        }
        cout << endl;
    }

    return 0;
}

But I want to generalize? Any guidance available?
 
Technology news on Phys.org
  • #2
google: ascii banner text

There should be plenty of programs for you to copy'n'paste.
 
  • #3
hmmm27 said:
google: ascii banner text

There should be plenty of programs for you to copy'n'paste.
I want to make that as a project to improve my programming skills though.
 
  • #4
Sure, so what are your ideas on how to go about it ?
 
  • #5
I'd like to do one for Nepali Language, but not sure if that's within my range of skills. About how idk. I'll listen to you guys and decide.
 
  • #6
Okay, then which part of your "programming skills" are you trying to improve upon ?
 
  • #7
shivajikobardan said:
I want to make a program that takes strings as input. eg: physicsforums. And writes that using x'es.
example c of physicsforums should look like this.
View attachment 327708
I've written the program for this.
Code:
#include <iostream>
using namespace std;
int main()
{
    int size;
    cout << "Enter the size of the pattern: ";
    cin >> size;

    for (int i = 0; i < size*2-1; i++)
    {
        for (int j = 0; j < size; j++)
        {
            if ((((i==0||i==2*size-2)&&j>1)||(i==1||i==2*size-3)&&(j==1||j==size-1))|| (j==0&&(i>1&&i<2*size-3)))
                cout << "X";
            else
                cout << " ";
        }
        cout << endl;
    }

    return 0;
}

But I want to generalize? Any guidance available?
IMO, generalization is the wrong way to go. The example letter, 'C', in the problem displays a large version of this letter in a 9 row by 5 column grid of 'X' characters and spaces.
Instead of using a complicated if statement, I would use 9 x 5 two-D arrays consisting of 1s and 0s, one for each letter. Given an input character, I would have the program look up the appropriate array in the data section and then use a nested for loop to print 'X' wherever the array contains 1, and a space where there is a 0.

A program like what I've described will have a very short code section, but a large section of data for the arrays, possibly an array of 9 by 5 arrays.

For starters, write a program that will print a large-form A, B, or C. You'll need to do a fair amount of work by hand using some graph paper to see how to fill in an array for each letter. You could do the same thing for the Nepali alphabet, but you might need to use larger array (10 x 10?) because the Nepali letters seem to have more curlicues than the Roman letters used in the English alphabet.
 
  • Like
Likes Merlin3189
  • #8
Mark44 said:
Instead of using a complicated if statement, I would use 9 x 5 two-D arrays consisting of 1s and 0s, one for each letter. Given an input character, I would have the program look up the appropriate array in the data section and then use a nested for loop to print 'X' wherever the array contains 1, and a space where there is a 0.
Or use 9x5 arrays of characters, each position containing an 'X' or a ' ' (blank space).

If I were doing this myself, I'd use a std::vector of std::strings, each string containing a row of the 9x5 matrix. I stopped using C-style arrays in C++ probably 25 years ago.
 
  • #9
Mark44 said:
IMO, generalization is the wrong way to go. The example letter, 'C', in the problem displays a large version of this letter in a 9 row by 5 column grid of 'X' characters and spaces.
Instead of using a complicated if statement, I would use 9 x 5 two-D arrays consisting of 1s and 0s, one for each letter. Given an input character, I would have the program look up the appropriate array in the data section and then use a nested for loop to print 'X' wherever the array contains 1, and a space where there is a 0.

A program like what I've described will have a very short code section, but a large section of data for the arrays, possibly an array of 9 by 5 arrays.

For starters, write a program that will print a large-form A, B, or C. You'll need to do a fair amount of work by hand using some graph paper to see how to fill in an array for each letter. You could do the same thing for the Nepali alphabet, but you might need to use larger array (10 x 10?) because the Nepali letters seem to have more curlicues than the Roman letters used in the English alphabet.
But How'd a computer program take unicode as an input? Is it possible? फिजिक्स फोरुम्स, this is nepali for physics forums. But how will a computer detect फि vs फ vs फो. you know any idea?
 
  • #10
Unfortunately, using Unicode in C++ appears to be a rather advanced topic. I tried a Google search for "c++ unicode string" and couldn't quickly find any simple descriptions.
 
  • #11
The raster method of producing banner script involves generating or finding a dotted font character pattern, as is used by dot-matrix or raster-scan displays. Those come in say, 5x8, 8x8 or 12x8 dot format.
There will be an LCD manufacturer who provides a dotted font data set for use with their displays. You might use one of those.

Search; "dotted font"
With; Nepali, Devanagari, Hindi, Ananda.

https://pijaeducation.com/arduino/l...r-custom-character-on-lcd-16x2-using-arduino/

http://fonthindi.blogspot.com/2014/05/dotted-hindi-font-for-complete-new-look.html
 
  • Like
Likes pbuk
  • #12
jtbell said:
Unfortunately, using Unicode in C++ appears to be a rather advanced topic. I tried a Google search for "c++ unicode string" and couldn't quickly find any simple descriptions.
There are several functions in the Visual Studio C standard library that can be used with Unicode characters, including wscanf_s and wprintf. Their headers are in the stdio.h or cstdio headers that can be included in a C++ program. I don't have any experience in working with Unicode characters, so can't say more than this.
There's some brief and not very helpful documentation of wscanf_s here -- https://learn.microsoft.com/en-us/c...s-scanf-s-l-wscanf-s-wscanf-s-l?view=msvc-170.
 
  • #13
Baluncore said:
The raster method of producing banner script involves generating or finding a dotted font character pattern, as is used by dot-matrix or raster-scan displays. Those come in say, 5x8, 8x8 or 12x8 dot format.
There will be an LCD manufacturer who provides a dotted font data set for use with their displays. You might use one of those.

Search; "dotted font"
With; Nepali, Devanagari, Hindi, Ananda.

https://pijaeducation.com/arduino/l...r-custom-character-on-lcd-16x2-using-arduino/

http://fonthindi.blogspot.com/2014/05/dotted-hindi-font-for-complete-new-look.html
I see Nepali=Hindi as everything is same. I'll have a look at it.
 

FAQ: Character pattern program -- Print large words using "X" characters

How does the character pattern program work?

The character pattern program prints large words using "X" characters by creating a pattern of "X" characters in the shape of the desired word. Each letter in the word is represented by a specific pattern of "X" characters.

Can I customize the size of the printed word?

Yes, you can customize the size of the printed word by adjusting the dimensions of the character pattern program. You can increase or decrease the number of "X" characters used to create the word to make it larger or smaller.

Is it possible to print words in different fonts or styles using the character pattern program?

No, the character pattern program is designed to print words using a simple pattern of "X" characters. It does not have the ability to replicate different fonts or styles.

How can I input a word to be printed using the character pattern program?

To input a word to be printed using the character pattern program, you can provide the word as a string input to the program. The program will then convert the word into a pattern of "X" characters based on the predefined patterns for each letter.

Are there any limitations to the character pattern program?

One limitation of the character pattern program is that it can only print words using the characters "X". It is not able to print words using other characters or symbols. Additionally, the size of the printed word may be limited by the dimensions of the program.

Back
Top