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

Click For Summary
SUMMARY

The discussion focuses on creating a C++ program that prints large words using 'X' characters based on user input. The initial implementation uses nested loops and conditional statements to form letters, specifically demonstrating the letter 'C'. Suggestions for improvement include utilizing 9x5 two-dimensional arrays for each letter to simplify the code and enhance scalability. Additionally, the conversation touches on the challenges of incorporating Unicode for languages like Nepali, indicating that advanced techniques are required for proper character representation.

PREREQUISITES
  • C++ programming fundamentals
  • Understanding of nested loops and conditional statements
  • Familiarity with two-dimensional arrays
  • Basic knowledge of Unicode and character encoding
NEXT STEPS
  • Implement a program using 9x5 arrays to represent letters in C++
  • Research techniques for handling Unicode strings in C++
  • Explore existing libraries for rendering ASCII art or banner text
  • Investigate dotted font data sets for various languages, including Nepali
USEFUL FOR

Programmers looking to enhance their C++ skills, particularly in graphical text representation, as well as developers interested in multilingual support and Unicode handling.

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.
 
  • Like
Likes   Reactions: Merlin3189
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
 
  • Like
Likes   Reactions: 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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 75 ·
3
Replies
75
Views
6K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K