(Erasing Characters from a string) Write a program that erases the sequences "by" and "BY" from a string.

What will be an ideal response?


```
// Program erases "by" or "BY" from strings.
#include
#include
using namespace std;

void deleteBy( string&, string ); // prototype

int main()
{
string s;

cout << "Enter a word: ";
cin >> s;

deleteBy( s, "by" ); // call function deleteBy to get rid of
deleteBy( s, "BY" ); // any occurrences of "by" and "BY"

cout << s << endl;
} // end main

// function to look for and get rid of "by" and "BY"
void deleteBy( string& sRef, string z )
{
int x = sRef.find( z ); // use member function find of class string

// until the end of the string is reached
while ( x <= sRef.length() )
{
sRef.erase( x, 2 ); // erase the occurrence of "by" or "BY"
x = sRef.find( z ); // find location of occurrence
} // end while
} // end function deleteBy
```
Enter a word: firstBYsecondby
firstsecond

Computer Science & Information Technology

You might also like to view...

AutoRecover periodically saves a file as you are working on it.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

When using a host-based intrusion detection system, what additional feature might be available to alert the system of any changes made to files that shouldn't change?

a. file integrity monitoring (FIM) b. file change management (FCM) c. file access auditing (FAA) d. file checksum watching (FCW)

Computer Science & Information Technology

A user cannot delete a record from a database table using the BindingNavigator control.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

?A company's risk assessment process can include numerous threats to the computers and networks. Which of the following can be considered an adverse event?

A. ?Distributed denial-of-service attack B. Email attachment with harmful worm C. Harmful virus D. All of the above

Computer Science & Information Technology