C PLEASE Write and test a function that takes nouns and retu

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

}

Solution

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] = \'\\0\';
      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:

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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site