Home Forums C Programming Please Help with this Question

Viewing 4 reply threads
  • Author
    Posts
    • #2157
      Erica3453kba
      Participant

      a. If noun ends in “y,” remove the “y” and add “ies.”
      b. If noun ends in “s,” “ch,” or “sh,” add “es.”
      c. In all other cases, just add “s.”
      Print each noun and its plural.

      In C++
      Thanks~

    • #3480
      GWILouisaxwzkla
      Participant

      What type of input are you using ( from the console , a file ) ??

    • #3481
      Erica3453kba
      Participant

      #include

    • #3482
      GWILouisaxwzkla
      Participant

      Not quite sure what you needed so I wrote this to read words from the keyboard into a character array. I haven’t tested this code much and the logic could probably be simplified….



      /****************************************************************
      * File Name : c:programshelptempCG.cpp
      * Date : November,17,2008
      * Comments : new project
      * Compiler/Assembler :
      *
      *
      *
      *
      *
      * Program Shell Generated At: 7:02:58 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


      #include < iostream.h >
      //#include < string.h >
      //#include < conio.h >
      //#include < math.h >
      //#include < iomanip >
      #include < ctype.h >
      #define MAX_LENGTH 50



      //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@



      //##################################################################################


      //main function ******************************

      int main ( )
      {

      char inputStr [ MAX_LENGTH ];
      int i = 0;
      cout << "Enter a string: " ;
      cin.getline ( inputStr , MAX_LENGTH );
      if ( inputStr [ 0 ] == 0 )
      return 0; //empty string

      cout << "output: " ;
      while ( inputStr [ i ] != 0 )
      {

      if ( inputStr [ i ] == 'y' && ( inputStr [ i + 1 ] == 0 || isspace ( inputStr [ i + 1 ] ) ) )
      {
      cout << "ies" ;
      i ++;
      }
      else if ( inputStr [ i ] == 's' && ( inputStr [ i + 1 ] == 0 || isspace ( inputStr [ i + 1 ] ) ) )
      {
      cout << "ses" ;
      i ++;
      }
      else if ( inputStr [ i ] == 's' && inputStr [ i + 1 ] == 'h' )
      {
      if ( inputStr [ i + 2 ] == 0 || isspace ( inputStr [ i + 2 ] ) )
      {
      cout << "shes" ;
      i += 2;
      }
      else
      cout << inputStr [ i ++ ];

      }
      else if ( inputStr [ i ] == 'c' && inputStr [ i + 1 ] == 'h' )
      {
      if ( inputStr [ i + 2 ] == 0 || isspace ( inputStr [ i + 2 ] ) )
      {
      cout << "ches" ;
      i += 2;
      }
      else
      cout << inputStr [ i ++ ];

      }

      else if ( isalnum ( inputStr [ i ] ) && ( isspace ( inputStr [ i + 1 ] ) || inputStr [ i + 1 ] == 0 ) )
      {
      cout << inputStr [ i ] << "s ";
      i ++;
      }
      else
      cout << inputStr [ i ++ ];


      }
      cout << endl;

      return 0;

      }




      output:


      Enter a string: church mickey sucks
      output: churches mickeies suckses
      Press any key to continue
    • #3483
      Erica3453kba
      Participant

      Thank you Alot..

Viewing 4 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.