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:
- The end curly brace of the if-condition
- 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