Exercise
Banner
Objetive
Write a C# program to imitate the basic Unix SysV "banner" utility, able to display big texts.
Example Code
using System; // Import the System namespace for basic functionality
class Program // Define the main class
{
static void Main() // The entry point of the program
{
Console.Write("Enter the text to display in a banner: "); // Prompt the user to input the text
string input = Console.ReadLine(); // Read the input from the user
// Call the method to display the banner with the input text
DisplayBanner(input);
}
// Method to display a banner with the given text
static void DisplayBanner(string text)
{
// Define the font for the banner using big letters
string[] letters = new string[]
{
"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z",
"A A BBBBB CCCCC D D EEEEE FFFFF G G H H I J K K L M M N N O O P P Q Q R R S S T T U U V V W W X X Y Y Z Z",
"A A B B C D D E F G G H H I J K K L MM MM NN NN OO OO PP PP QQ QQ RR RR S T T U U V V W W X X Y Y Z",
"AAAAA BBBBB C D D EEEE FFFFF GGGGG HHHHH I J KKKK L M M M N N O O PPPP Q Q RRRR SSSS T T U U V V W W X X Y Y Z",
"A A B B C D D E F G G H H I J K K L M M NN NN OO OO PP P Q Q RR RR S T T U U V V W W X X Y Y Z",
"A A BBBBB CCCCC DDDDD EEEEE F G G H H I J K K LLLLL M M N N O O P P Q Q R R SSSS T T UUUU V V W W X X Y Y Z Z"
};
// Loop through each row in the big letters to create the banner
for (int i = 0; i < 6; i++) // We have 6 lines for the letters
{
foreach (char c in text.ToUpper()) // Iterate through each character in the input text (convert to uppercase)
{
if (c == ' ') // If the character is a space, just print a space in the banner
{
Console.Write(" "); // Adjust space size for proper alignment
}
else if (c >= 'A' && c <= 'Z') // Check if the character is a valid letter (A-Z)
{
// Calculate the position of the character in the alphabet (0-25)
int charIndex = c - 'A';
// Calculate the starting index for the letter in the string (each letter is 6 characters long)
int startIndex = charIndex * 6;
// Check if the startIndex is within bounds of the current row string
if (startIndex + 6 <= letters[i].Length)
{
// Print the corresponding row of the letter in the banner
Console.Write(letters[i].Substring(startIndex, 6)); // Use length 6 to include the space
}
}
else
{
// If the character is invalid (not A-Z), just print spaces
Console.Write(" ");
}
}
Console.WriteLine(); // Move to the next line in the banner
}
}
}