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>#include <string>using namespace std;int main() {string userInput;getline(cin, userInput);/* Your solution goes here */return 0;}Please help me with this problem using c++.

Question
Asked Oct 5, 2019
745 views

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>
#include <string>
using namespace std;

int main() {
string userInput;

getline(cin, userInput);

/* Your solution goes here */

return 0;
}

Please help me with this problem using c++.

check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1

To add code segments in the below given program code, so that the code will print "Censored" if user input contains the word "darn", else print user input.

For example, if the user input is , “darn”

Then output is, “censored”

And if the input string does not consist of word darn then the program will print, the user input as it is:

Suppose the user input is, “my name”

Then output is, “my name”.

Step 2

Program code:

 

#include <iostream>

#include <string>

using namespace std;

int main()

{

string userInput;

getline(cin, userInput);

/* Your solution goes here */

/*declaring an integer variable search to find that the

user entered string consist of word darn or not*/

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

    //if statement will execute if the user input string consists of darn word

    if (search >= 0)

    {

        cout << "Censored" << endl;

    }

//else statement will execute if the user input string does not consist of darn word

   else

    {

        cout << userInput << endl;

    }

return 0;

}

Step 3

Output of the above program if user in...

help_outline

Image Transcriptionclose

darn demo Censored

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz = 2; y= z+x;en...

A: Pass by value copies the value of argument and passes it to the parameter. Hence, the final value of...

question_answer

Q: Is the file structure of Windows 10 File Explorer or hierarchy?

A: File structure of an operating system cannot be differentiated as file explorer or hierarchy.

question_answer

Q: Who is Alan Turnig ?

A: Alan Turing was born in the year 1912 and died in the year 1954. He was a mathematician, computer sc...

question_answer

Q: rewrite the function F = (A ⊕ B) ⊕ C without the XOR operator, ⊕.

A: Boolean simplifications used to solve the given problem:

question_answer

Q: Java is considered to be “safe” from buffer overflows. Does that make it more appropriate to use as ...

A: Security is very crucial part for all the  development projects running in any organization and Java...

question_answer

Q: I can't figure this one out for the life of me. I've been stuck on it for 4 hours now... HELP! The p...

A: import re inputs = 0numbers_sum = 0 # enter the stringstring = input('Enter a string: ') # condition...

question_answer

Q: Hello, I am using the Intro to Java programmming and data structures by Y. Daniel Liang. Our profess...

A: A java program to check the user’s input is a factor of random number generated is given below;Progr...

question_answer

Q: Subject: Computer Organization I 1.a) How many milliseconds (ms) are in 1 second?b) How many microse...

A: 1. Usually, time is measured in power of 10.There are 1,000 milliseconds in 1 second.There are 1,000...

question_answer

Q: 1. (3.12 in 8e) What does the following program print? Note: Don't just give me the output - tell me...

A: 1)The given code snippet is used to print the squares of numbers from 1 to 10. It calculates the sum...