Answer to Question #185377 in C# for angelo r reyes

Question #185377

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
2021-04-25T12:07:53-0400
using System;


namespace Questions
{
    class Program
    {
        public static string FormsPlural(string noun)
        {
            if (noun[noun.Length - 1] == 'y')
            {
                noun = noun.Substring(0, noun.Length - 1);
                noun += "ies";
            }
            else if (noun.Substring(noun.Length - 2).Equals("ch") || 
                        noun.Substring(noun.Length - 2).Equals("sh"))
            {
                noun += "es";
            }
            else
                noun += "s";


            return noun;
        }
        static void Main()
        {
            Console.Write("Enter nouns (split by space): ");
            string nouns = Console.ReadLine();


            string[] words = nouns.Split();


            for(int i = 0; i < words.Length; i++)
                words[i] = FormsPlural(words[i]);


            Console.Write("\nPlurals: ");
            foreach (string word in words)
                Console.Write(word + " ");


            Console.ReadKey();
        }
    }
}

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