C++: Word Censor - Print "Censored

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

Discussion Overview

The discussion revolves around a C++ programming task that involves censoring a specific word ("darn") in user input. Participants seek assistance with implementing a solution, exploring various methods for substring searching and handling user input.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant expresses confusion about how to implement the censoring functionality and requests help.
  • Another participant suggests reading the "Searching and Substrings" section of a webpage for guidance.
  • A participant notes the absence of a textbook for the class and mentions the lack of useful lecture notes.
  • Further discussion highlights the need to manually enumerate substrings of a specific length to check for the word "darn".
  • Another participant asks for specific commands that could be used, such as find() or substr().
  • One participant recommends using the find() function for a simpler solution, while also discussing the need for an algorithm if standard functions are not allowed.

Areas of Agreement / Disagreement

Participants generally agree on the need for substring searching methods, but there is no consensus on the best approach or whether to use standard functions.

Contextual Notes

Some participants mention the potential restriction of not using standard functions, which may affect the proposed solutions. There is also uncertainty regarding the specific commands needed for the task.

Who May Find This Useful

Students learning C++ programming, particularly those working on string manipulation and substring searching tasks.

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
35K
  • · 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