Objective
Write a C# program to imitate the basic Unix SysV "banner" utility, able to display big texts.
Write Your C# Exercise
C# Exercise Example
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(" ");
}
else
{
// Calculate the position of the character in the alphabet (0-25)
int charIndex = c - 'A';
// Check if the character is valid (A-Z)
if (charIndex >= 0 && charIndex < 26)
{
// Print the corresponding row of the letter in the banner
Console.Write(letters[i].Substring(charIndex * 6, 5) + " ");
}
}
}
Console.WriteLine(); // Move to the next line in the banner
}
}
}
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
This Exercise in C# involves creating a program that asks the user for a text string and displays a right-aligned triangle using that string. The triang...
This Exercise in C# involves creating a program that asks the user for a text string and performs three specific transformations on it. The program must...
This Exercise in C# involves creating a struct to store two pieces of data for a person: their name and their date of birth. The date of birth...
This Exercise in C# involves creating a program that asks the user for 10 integer numbers (from -1000 to 1000), sorts them, and then displays them in ascending...
This Exercise in C# involves creating a program that declares a 70x20 two-dimensional array of characters and "draws" 80 letters (e.g., 'X') in random positions withi...
This Exercise in C# involves creating a program that declares a 70x20 two-dimensional array of characters and "draws" a circumference with a radius of 8 inside it. To...