Home › Forums › C Programming › Please Help with this Question
- This topic has 4 replies, 2 voices, and was last updated 16 years, 1 month ago by Erica3453kba.
Viewing 4 reply threads
- AuthorPosts
- November 18, 2008 at 9:30 am #2157Erica3453kbaParticipant
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~ - November 18, 2008 at 9:16 pm #3480GWILouisaxwzklaParticipant
What type of input are you using ( from the console , a file ) ??
- November 19, 2008 at 2:27 am #3481Erica3453kbaParticipant
#include
- November 19, 2008 at 7:35 pm #3482GWILouisaxwzklaParticipant
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….
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102<br /><br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />#include < ctype.h ><br />#define MAX_LENGTH 50<br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />char inputStr [ MAX_LENGTH ];<br />int i = 0;<br />cout << "Enter a string: " ;<br />cin.getline ( inputStr , MAX_LENGTH );<br />if ( inputStr [ 0 ] == 0 )<br />return 0; //empty string<br /><br />cout << "output: " ;<br />while ( inputStr [ i ] != 0 )<br />{<br /><br />if ( inputStr [ i ] == 'y' && ( inputStr [ i + 1 ] == 0 || isspace ( inputStr [ i + 1 ] ) ) )<br />{<br />cout << "ies" ;<br />i ++;<br />}<br />else if ( inputStr [ i ] == 's' && ( inputStr [ i + 1 ] == 0 || isspace ( inputStr [ i + 1 ] ) ) )<br />{<br />cout << "ses" ;<br />i ++;<br />}<br />else if ( inputStr [ i ] == 's' && inputStr [ i + 1 ] == 'h' )<br />{<br />if ( inputStr [ i + 2 ] == 0 || isspace ( inputStr [ i + 2 ] ) )<br />{<br />cout << "shes" ;<br />i += 2;<br />}<br />else<br />cout << inputStr [ i ++ ];<br /><br />}<br />else if ( inputStr [ i ] == 'c' && inputStr [ i + 1 ] == 'h' )<br />{<br />if ( inputStr [ i + 2 ] == 0 || isspace ( inputStr [ i + 2 ] ) )<br />{<br />cout << "ches" ;<br />i += 2;<br />}<br />else<br />cout << inputStr [ i ++ ];<br /><br />}<br /><br />else if ( isalnum ( inputStr [ i ] ) && ( isspace ( inputStr [ i + 1 ] ) || inputStr [ i + 1 ] == 0 ) )<br />{<br />cout << inputStr [ i ] << "s ";<br />i ++;<br />}<br />else<br />cout << inputStr [ i ++ ];<br /><br /><br />}<br />cout << endl;<br /><br />return 0;<br /><br />}<br /><br /><br /><br /><br />output:
12345<br />Enter a string: church mickey sucks<br />output: churches mickeies suckses<br />Press any key to continue<br /> - November 20, 2008 at 3:50 am #3483Erica3453kbaParticipant
Thank you Alot..
- AuthorPosts
Viewing 4 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.