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.
 

What is a "Character pattern program"?

A character pattern program is a computer program that prints words or phrases using specific characters or symbols, creating a visual pattern. In this case, the program will use the letter "X" to create large words.

What is the purpose of this program?

The purpose of this program is to create a visual representation of words or phrases using a specific character. It can be used for decorative purposes or to create unique designs.

How does the program work?

The program works by taking a word or phrase as input and then using a loop to print out each letter using "X" characters. The number of "X" characters used for each letter is determined by the size of the word and the desired pattern.

What is the complexity of this program?

The complexity of this program depends on the length of the word or phrase and the desired pattern. Generally, it would have a time complexity of O(n) where n is the length of the word or phrase.

Can this program be customized?

Yes, this program can be customized to use different characters or symbols and create different patterns. It can also be modified to print words in different sizes or orientations.

Similar threads

  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
5
Views
884
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
3
Views
729
Replies
10
Views
960
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
6
Views
8K
Back
Top