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

C++ PLEASE Write and test a function that takes nouns and return their plurals o

ID: 3790982 • Letter: C

Question

C++ PLEASE

Write and test a function that takes nouns and return their plurals on the basis of the following rules

1. if noun ends in “y” remove the “y” and add “ies”

2. if noun ends in “s” or “sh” add “es”

3. all other cases just add “s”

Print each noun and its plural. Try the following nouns.

chair diary boss circus fly dog clue dish

Structure of the program:

char* change_to_plural ( char* input_string ); // Implement this function

void main() {

//Declare required variables

//Read string

//Convert word read to represent plural by calling function

//Print the plural word

}

Explanation / Answer

PROGRAM CODE:

#include <iostream>
#include <string.h>
using namespace std;

char* change_to_plural ( char* input_string )
{
   int len = strlen(input_string);
   //checking for y at the end
   if(input_string[len-1] == 'y')
   {
      input_string[len-1] = '';
      strcat(input_string, "ies");
   }
   //checking for s or s and h
   else if(input_string[len-1] == 's' || (input_string[len-2] == 's' && input_string[len-1] == 'h'))
      strcat(input_string, "es");
   else
   //all other words
      strcat(input_string, "s");
   return input_string;
}
int main() {
   //using char array to get the noun from the user
   char noun[100];
   cout<<"Enter the noun: ";
   cin>>noun;
   //passing the noun as a pointer to the function
   change_to_plural (noun);
   //the noun variable directly gets altered
   cout<<" Plural: "<<noun<<endl;
   return 0;
}

OUTPUT:

RUN #1:

Run #2:

Run #3:

Run #4:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote