Banner - C# Programming Exercise

This Exercise in C# involves creating a program that imitates the basic Unix SysV "banner" utility, allowing you to display large texts in a similar manner. The purpose of this Exercise is to teach you how to work with text strings and control their display in the console in a creative way. In this Exercise, you will need to handle user inputs to allow the customization of the text that will be shown in an enlarged format.

The program should take a text input and display it in large letters using ASCII characters. This type of project is very useful for developing skills in C# such as handling strings, text manipulation, and user interaction with the console. It is a great way to familiarize yourself with the fundamental aspects of C# programming while building a tool with functionalities similar to those found in Unix-based operating systems.

C# is a powerful and versatile programming language, and with this Exercise, you'll learn how to apply fundamental concepts in a hands-on practice that is both educational and fun. This Exercise is a great opportunity to test your knowledge and learn something new in a creative way!

 Category

Arrays, Structures and Strings

 Exercise

Banner

 Objective

Write a C# program to imitate the basic Unix SysV "banner" utility, able to display big texts.

 Write Your C# Exercise

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
        }
    }
}

 Share this C# exercise

 More C# Programming Exercises of Arrays, Structures and Strings

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#.

  •  Triangle right side

    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...

  •  Strings manipulation

    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...

  •  Nested structs

    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...

  •  Sort data

    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...

  •  Two dimensional array as buffer for screen

    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...

  •  Two dimensional array 2: circunference on screen

    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...