Write a function for the following prototype: void addLetterS( const char orig[]
ID: 3762070 • Letter: W
Question
Write a function for the following prototype:
void addLetterS( const char orig[], char plural[])
The function will copy the "orig" character array into the character array "plural" adding an s at the end.
For example if the orig array contained "hello" then the plural array will result in "hellos"
Use the following sample driver:
char word[10];
addLetterS( school , word); // copy word into school and add an 's' to the end
cout << word << endl; // will output the contents of word i.e. "schools"
HINT - Use a loop incrementing i until orig[i] equals ''...when the loop stops move 's' into that position and then
move '' into the following position.
Explanation / Answer
void addLetterS(const char orig[],char plural[]){
int i;
for(i = 0; orig[i] != ''; i++)
plural[i] = orig[i];
plural[i++] = 's';
plural[i] = '';
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.