C++: Word Censor - Print "Censored

  • C/C++
  • Thread starter ineedhelpnow
  • Start date
In Summary, the userInput contains the word "darn" if and only if the string contains a substring of length 4 equal to "darn".
  • #1
ineedhelpnow
651
0
Print "Censored" if user text contains the word "darn", else print userInput. end with new line.

Sample program:

Code:
#include 
#include  
using namespace std;

int main() {
   string userInput;

   userInput = "That darn cat.";
   <student code>
    

   return 0;
}

I'm super lost on this. I could definitely use some help/hints. Thanks.
 
Technology news on Phys.org
  • #2
Read the "Searching and Substrings" section of this page, or, better, read your textbook or lecture notes.
 
  • #3
we don't have a textbook for the class. he doesn't give us anything to take notes on.
 
  • #4
ineedhelpnow said:
he doesn't give us anything to take notes on.
Aren't you supposed to bring your own notebooks? Anyway, if you have questions after reading the web page linked above, let us know.
 
  • #5
lol i meant in his lecture there is nothing useful for us to record down. he goes over the homework and he'll be like ok do this problem and then do this oh and don't do this lesson. and then he'll just talk at as about computer science or computer engineering.
 
  • #6
So the string contains the word "darn" if and only if the string contains a substring of length 4 equal to "darn". How would you enumerate all substrings of length 4 in a string? How would you check if they are equal to "darn"?

I'm assuming you need to do it manually here, since there are standard functions for doing this sort of thing already.
 
  • #7
:eek: I am still stuck on this problem. i really don't understand it all. can someone tell me what command i need to use at least. i might be able to figure the rest out. like do i use: find(), substr()?
 
  • #8
It is easier to use the function [m]find()[/m] described in the link I gave in post #2. Then checking whether the string is censored is a one-liner. If you were said not to use standard functions, then we need to come up with an algorithm that checks for occurrence of a substring. In that case, you can pretend you have a sequence of letter blocks. Describe how you would check them one at a time (this is important) to find a substring.
 

FAQ: C++: Word Censor - Print "Censored

What is C++?

C++ is a high-level, general-purpose programming language that was developed by Bjarne Stroustrup in 1983. It is an extension of the C programming language and is commonly used for developing operating systems, games, and other software applications.

How does the "Word Censor" program work?

The "Word Censor" program works by taking in a string of text and replacing any words that match a given list of banned words with the word "Censored". This is done using various string manipulation techniques and conditional statements in the C++ programming language.

What is the purpose of censoring words in a program?

The purpose of censoring words in a program is to filter out offensive or inappropriate language from being displayed to users. This is often used in online communities, social media platforms, and other applications where users may interact with each other.

Can the "Word Censor" program be modified to censor different words?

Yes, the "Word Censor" program can be modified to censor different words by simply changing the list of banned words in the program's code. This allows for flexibility in the program's usage and can be tailored to fit specific needs.

Is C++ the only programming language that can be used for the "Word Censor" program?

No, C++ is not the only programming language that can be used for the "Word Censor" program. Other languages such as Java, Python, and C# can also be used to achieve the same functionality, albeit with slightly different syntax and implementation.

Similar threads

Replies
2
Views
5K
Replies
4
Views
6K
Replies
14
Views
32K
Replies
1
Views
4K
Replies
40
Views
3K
Replies
118
Views
8K
Replies
22
Views
3K
Back
Top