Answer to Question #325786 in C# for chi

Question #325786

6.9.(Write a program using string functions)

Write a program that takes nouns and forms their plurals on the basis of these rules:

a. If a noun ends in “y”, remove the”y” and add “ies”

b. If a noun ends in "s”, “ch” or “sh”, add "es”

c. In all other cases, just add “s”


1
Expert's answer
2022-04-08T09:01:39-0400
internal class Program
    {
       
        static void Main(string[] args)
        {
            Console.Write("Enter your word:");
            string word = Console.ReadLine();
           
            Console.WriteLine($"Your word is plural: {PluralForm(word)}");
            Console.ReadKey();
        }
        public static string PluralForm(string word)
        {
            string[] ends = { "s", "ch", "y", "sh" };
            foreach (string letters in ends)
            {
                if (word.EndsWith(letters) & letters == "y")
                {
                    word = word.Remove(word.Length - 1, 1);
                    return word += "ies";
                    
                }
                else if (word.EndsWith(letters))
                {
                    return word += "es";
                }
            }
            return word += "s";
        }


    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS