Question

In: Computer Science

Print "Censored" if userInput contains the word "darn", else print userInput. End with newline. Note: These...

Print "Censored" if userInput contains the word "darn", else print userInput. End with newline.

Note: These activities may test code with different test values. This activity will perform three tests, with userInput of "That darn cat.", then with "Dang, that was scary!", then with "I'm darning your socks.". See "How to Use zyBooks". .

Also note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.

#include <iostream>
#include <string>
using namespace std;

int main() {
string userInput;

userInput = "That darn cat.";

/* Your solution goes here */

return 0;
}

Solutions

Expert Solution

Provided code is done as per your requirements.

  • "Screen shot program code" for better understanding.
  • "Code to copy" for run the program in your IDE.

Test Code 1:

userInput of "That darn cat."

Code Image:

Sample Output:

Code to Copy:

#include<iostream>

#include<string>

using namespace std;

int main() {

string userInput;

    userInput = "That darn cat.";

    /* Your solution goes here */

    int word = userInput.find("darn");

    if (word > 0){

        cout << "Censored" << endl;

    }

    else{

        cout << userInput << endl;

    }

    return 0;

}

Test Code 2:

userInput of "Dang, that was scary!"

Code Image:

Sample Output:

Code to Copy:

#include<iostream>

#include<string>

using namespace std;

int main() {

string userInput;

    userInput = "Dang, that was scary!";

    /* Your solution goes here */

    int word = userInput.find("darn");

    if (word > 0){

        cout << "Censored" << endl;

    }

    else{

        cout << userInput << endl;

    }

    return 0;

}

Test Code 3:

userInput of "I'm darning your socks."

Code Image:

Sample Output:

Code to Copy:

(3)

#include<iostream>

#include<string>

using namespace std;

int main() {

string userInput;

    userInput = "I'm darning your socks.";

    /* Your solution goes here */

    int word = userInput.find("darn");

    if (word > 0){

        cout << "Censored" << endl;

    }

    else{

        cout << userInput << endl;

    }

    return 0;

}


Related Solutions

Print "Censored" if userInput contains the word "darn", else print userInput. End with newline. Ex: If...
Print "Censored" if userInput contains the word "darn", else print userInput. End with newline. Ex: If userInput is "That darn cat.", then output is: Censored Ex: If userInput is "Dang, that was scary!", then output is: Dang, that was scary! Note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message. #include <iostream>...
(Java Zybooks) Print "Censored" if userInput contains the word "darn", else print userInput. End with newline....
(Java Zybooks) Print "Censored" if userInput contains the word "darn", else print userInput. End with newline. Ex: If userInput is "That darn cat.", then output is: Censored Ex: If userInput is "Dang, that was scary!", then output is: Dang, that was scary! Note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message....
Print "Censored" if userInput contains "darn", else print iserInput. End with newline. Ex: If userInput is...
Print "Censored" if userInput contains "darn", else print iserInput. End with newline. Ex: If userInput is "That darn cat", then output is:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT