Reputation: 43
for example, a have this function that prints a big "A"
void printA(){
cout<<"0000000\n0 0\n0 0\n0000000\n0 0\n0 0\n";
}
0000000
0 0
0 0
0000000
0 0
0 0
I have all the alphabet, is there a way I can print the big letters horizontally? like:
0000000 0000000 0000000
0 0 0 0 0 0
0 0 0 0 0 0
0000000 0000000 0000000
0 0 0 0 0 0
0 0 0 0 0 0
the goal of the program is to print the user's input with these big letters, vertically or horizontally.
here is a resumed version of my program:
void printA(){
cout<<"0000000\n0 0\n0 0\n0000000\n0 0\n0 0\n"<<endl;
}
void printChar(char c){
c = toupper(c);
if (c=='A')
printA();
}
int main(){
string sentence;
cout<<"enter sentence: ";
cin>> sentence;
for(unsigned int i = 0; i<sentence.length(); i++) {
char c = sentence[i];
if(c=='a')
printA();
}
return 0;
}
I made the letter functions with the "\n" to save lines, another option is to make them like this:
void printA(){
cout << "0000000" << endl;
cout << "0 0" << endl;
cout << "0 0" << endl;
cout << "0000000" << endl;
cout << "0 0" << endl;
cout << "0 0" << endl;
}
if is not possible to print them next to each other in the way i have them, i will rewrite them, but please tell me how to print them in horizontal form :( thank you!
I have the following alerts:
main.cpp:29:23: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
for (char c : text)
^
main.cpp:31:37: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
std::cout << alphabet[c - 'A'][line] << " ";
Upvotes: 1
Views: 4909
Reputation: 32627
If you can store the lines of your characters in a different format (here, a 2D array) like so:
const int LINES_PER_CHAR = 6;
const char* alphabet[][LINES_PER_CHAR] =
{
/* A */ { "0000000", "0 0", "0 0", "0000000", "0 0", "0 0" },
/* B */ { "000 ", "0 0", "0 0", "000 ", "0 0", "0000" }
...
};
…, then you can print the characters like this:
void PrintBigString(const std::string& text)
{
for (int line = 0; line < LINES_PER_CHAR; ++line)
{
for (char c : text)
{
std::cout << alphabet[c - 'A'][line] << " ";
}
std::cout << std::endl;
}
}
Ideally, you should add a sanity check that makes sure that you have the template for the current character in the string.
Variation for non-C++11 compilers:
void PrintBigString(const std::string& text)
{
for (int line = 0; line < LINES_PER_CHAR; ++line)
{
for (int i = 0; i < text.size(); ++i)
{
std::cout << alphabet[text[i] - 'A'][line] << " ";
}
std::cout << std::endl;
}
}
Upvotes: 4