Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***I am using visual studios*** Create a program that includes a function called

ID: 3728474 • Letter: #

Question

***I am using visual studios***

Create a program that includes a function called spaced that takes a string and returns a string with spaces beteen each character (including spaces). For example, given “hello” as the input, the function should return “h e l l o ”, which is the spaced string of “hello”.

The main function should prompt the user to input a string until the user types “Q” For each string input call the function with the string and display the result. Note that the user input string may contain white spaces.

Example input/output sessions:

Explanation / Answer

below is the cde of the above problem:

code:

using System;
namespace StringSplit
{
    class Program
    {
        private static string str1;
        static void Main(string[] args)
        {
            string str; //create a string variable
            do
            {
                str = Console.ReadLine(); //read a string from keyboard
                if (str == "Q" || str == "q")
                    Environment.Exit(0); //exit
                Console.WriteLine(space(str));//call the function space print the string into character with space
            } while (true); //input the string untill user type Q to quit
         
        }

        public static string space(string str)
        {
            str1 = ""; //set the str1 string to null
            for (int i = 0; i < str.Length; i++) //llop to string of length
            {
                str1+=str[i] + " "; //prints each character of the string with space
            }          
            return str1; //return string
        }
    }
}

smaple output:

Hello
H e l l o
CBU
C B U
C++ is fun!
C + +   i s   f u n !

Q