7
Answers

code for hotel menu app using c#

hi,
 I am a starter, 
how to write code for hotel menu application using c#. please help ??
 
Thanks in advance  
Answers (7)
3
Jithu Thomas

Jithu Thomas

194 10.2k 108.1k Jul 24
using System;
using System.IO;

class Program
{
    static void Main()
    {
        string inputFilePath = "input.txt";  // Path to the input file
        string outputFilePath = "output.txt"; // Path to the output file

        // Define column lengths
        int[] columnLengths = { 1, 21, 51, 81, 131, 141 };

        // Read all lines from the input file
        string[] lines = File.ReadAllLines(inputFilePath);

        // Create an array to hold the formatted lines
        string[] formattedLines = new string[lines.Length];

        // Process each line
        for (int i = 0; i < lines.Length; i++)
        {
            string line = lines[i];
            string formattedLine = "";

            // Split the line into columns based on the column lengths
            int currentIndex = 0;
            foreach (int length in columnLengths)
            {
                if (currentIndex < line.Length)
                {
                    int lengthToUse = Math.Min(length, line.Length - currentIndex);
                    string column = line.Substring(currentIndex, lengthToUse).Trim();
                    formattedLine += column.PadRight(length) + " ";
                    currentIndex += lengthToUse;
                }
            }

            // Add the formatted line to the array
            formattedLines[i] = formattedLine;
        }

        // Write the formatted lines to the output file
        File.WriteAllLines(outputFilePath, formattedLines);

        Console.WriteLine("File formatted successfully.");
    }
}

Dear 

Try this,

Accepted
3
Rajadurai

Rajadurai

1k 662 3.8k Jul 24

Hi Jithu,

 

Its Working thank you