(Words Ending in “r” or “ay”) Write a program that reads in several strings and prints only those ending in “r” or “ay”. Only lowercase letters should be considered.

What will be an ideal response?


```
// Program determines if string ends in 'r' or "ay".
#include
#include
using namespace std;

int main()
{
string s[ 5 ]; // declare a string array

// loop to get user input
for ( int i = 0; i < 5; i++ )
{
cout << "Enter a word: ";
cin >> s[ i ];
} // end for

// use function rfind to find occurrences of "ay" or 'r'
for ( int j = 0; j < 5; j++ )
{
// does the word end in "ay" or 'r'?
if ( ( ( s[ j ].rfind( "ay" ) == s[ j ].length() - 2 ) )
|| ( s[ j ].rfind( "r" ) == s[ j ].length() - 1 ) )
cout << s[ j ] << endl; // if match, display it
} // end for
} // end main
```
Enter a word: bicycle
Enter a word: car
Enter a word: tree
Enter a word: canary
Enter a word: iron
car

Computer Science & Information Technology

You might also like to view...

ZENWorks and HFNetChkPro are examples of which of the following?

A) Antivirus software B) IDS C) Patch management systems D) Viruses

Computer Science & Information Technology

With reference to system building, explain why you may sometimes have to maintain obsolete computers on which large software systems were developed.

What will be an ideal response?

Computer Science & Information Technology

The ONERROR event is used to handle all of these except.

(a) User errors. (b) Programmatic errors. (c) Browser errors. (d) Object location errors.

Computer Science & Information Technology

The size of the page is determined by the ____________________ property of the link element.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology