/*************************************************************************** Program: A2Q4.cpp Purpose: To form plurals of English nouns according to the following rules if noun ends in "y", remove "y" and add "ies" if noun ends in "s", "ch" or "sh", add "es" otherwise, just add "s" ****************************************************************************/ #include #include using namespace std; // Function Prototypes void plurals(string str); int main(){ string input; // get word from user input cout << "\nPlease enter a word: "; cin >> input; // call function plurals plurals(input); } /**************************************************************************** Function: plurals Purpose: form the plural of an English noun Parameters: string Return Value: NONE ****************************************************************************/ void plurals(string str){ string end, end2, output; end = str[str.length()-1]; // get last letter in string end2 = str[str.length()-2]; //get 2nd last letter in string if (end == "y") // string ends in y // get substring of noun up to 2nd last letter // concatenate "ies" to end of substring output = str.substr(0,(str.length()-1)) + "ies"; else if (end == "s") // string ends in "s" // concatenate "es" to end of string output = str + "es"; else if (end == "h"){ // string ends in "h" // check 2nd last letter to see if it is a "c" or an "s" if (end2 == "c" || end2 == "s") // if yes, concatenate "es" to end of string output = str + "es"; } else // concatenate "s" to end of string output = str + "s"; // output string cout << "\nThe plural of " << str << " is: " << output << endl; }