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


#include


using namespace std;


int main() {


string userInput;


getline(cin, userInput);


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


if (isPresent > 0){


cout << "Censored" << endl; /* Your solution goes here */


return 0;


}

Respuesta :

Answer:

if(userInput.indexOf("darn") != -1) {

        System.out.println("Censored");

     }

     else {

        System.out.println(userInput);

     }

Explanation:

The code segment is written in C++ and it must be completed in C++.

To complete the code, we simply replace  /* Your solution goes here */ with:

}

else{

   cout<<userInput;

}

The missing code segments in the program are:

  1. The end curly brace of the if-condition
  2. The else statement that will print userInput, if string "darn" does not exist in the input string.

For (1), we simply write } at the end of the 9th line of the given code segment.

For (2), the else condition must be introduced, and it must include the statement to print userInput.

The complete code where comments are used to explain each line is as follows:

#include<iostream>

#include<string>

using namespace std;

int main() {

//This declares userInput as string

string userInput;

//This gets input for userInput

getline(cin, userInput);

//This checks if "darn" is present in userInput

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

//If isPresent is 0 or more, it means "darn" is present

if (isPresent >= 0){

//This prints Censored

   cout << "Censored" << endl;}

//If otherwise

else{

//The userInput is printed

cout<<userInput;

}

return 0;

} // Program ends here

See attachment for the complete code and a sample run

Read more about C++ programs at:

https://brainly.com/question/12063363

Ver imagen MrRoyal