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”
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();
}
}
}
Comments
Leave a comment