C++: Word Censor - Print "Censored

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on implementing a C++ program that prints "Censored" if the user input contains the substring "darn". Participants suggest using the find() function for substring searching, which simplifies the task to a one-liner. The conversation highlights the importance of understanding substring enumeration and manual checking methods if standard functions are restricted. Key programming concepts such as string manipulation and substring comparison are emphasized throughout the discussion.

PREREQUISITES
  • C++ programming fundamentals
  • Understanding of string manipulation in C++
  • Knowledge of substring searching techniques
  • Familiarity with the find() function in C++
NEXT STEPS
  • Research C++ string manipulation techniques
  • Learn about the find() function and its applications
  • Explore algorithms for substring searching without standard library functions
  • Study examples of input validation and output formatting in C++
USEFUL FOR

C++ beginners, programming students, and anyone interested in string processing and substring searching techniques in C++.

ineedhelpnow
Messages
649
Reaction score
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
Read the "Searching and Substrings" section of this page, or, better, read your textbook or lecture notes.
 
we don't have a textbook for the class. he doesn't give us anything to take notes on.
 
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.
 
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.
 
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.
 
:o 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()?
 
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 14 ·
Replies
14
Views
34K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 5 ·
Replies
5
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 40 ·
2
Replies
40
Views
3K
  • · Replies 118 ·
4
Replies
118
Views
10K
  • · Replies 22 ·
Replies
22
Views
4K