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

AI Thread Summary
The discussion revolves around creating a program that takes input strings and outputs them in a stylized format using 'X' characters. The initial code provided demonstrates how to print a specific letter, 'C', using a nested loop structure. Participants suggest generalizing the approach by using 2D arrays to represent each letter, allowing for easier scalability and the ability to print multiple characters. There is a focus on the potential complexity of incorporating Unicode for languages like Nepali, with suggestions to explore existing resources and libraries for handling Unicode in C++. The conversation also touches on the need for a suitable font representation for different scripts, emphasizing that creating a program for the Nepali alphabet may require larger matrices due to its unique characters. Overall, the thread highlights the importance of foundational programming skills and the challenges of working with diverse character sets in programming.
shivajikobardan
Messages
637
Reaction score
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
google: ascii banner text

There should be plenty of programs for you to copy'n'paste.
 
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.
 
Sure, so what are your ideas on how to go about it ?
 
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.
 
Okay, then which part of your "programming skills" are you trying to improve upon ?
 
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.
 
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.
 
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
 
  • #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.
 
Back
Top