Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Unnecessary Censorship2. It’s easy: 1. Read in a text file. 2. Replace all 4 let

ID: 3779479 • Letter: U

Question

Unnecessary Censorship2. It’s easy: 1. Read in a text file. 2. Replace all 4 letter words with ****. 3. Write the result back out to a new file. For example, text.txt contains the text: Hullabaloo, Caneck! Caneck! Hullabaloo, Caneck! Caneck! Good-bye to texas university So long to the orange and the white Good luck to dear old Texas Aggies They are the boys that show the real old fight "The eyes of Texas are upon you" That is the song they sing so well Invokethecensor function: >> censor('text.txt'); The file text_censored.txt contains the censored text: Hullabaloo, Caneck! Caneck! Hullabaloo, Caneck! Caneck! Good-bye to texas university So **** to the orange and the white **** **** to **** old Texas Aggies **** are the **** **** **** the **** old fight "The **** of Texas are **** you" **** is the **** **** **** so **** Note: the output file name is simply the input filename with _censored appended to the end. >> in = 'text.txt'; >> out = [in(1:end-4) '_censored' in(end-3:end)] out = text_censored.txt

Explanation / Answer

#include <bits/stdc++.h>

using namespace std;

int main ()
{
// Open a file "ReadMe.txt"
std::ifstream ifsInputFile ("wrd");
ofstream outfile;
outfile.open("result");

if (ifsInputFile.is_open ())
{

   std::string strLine;

   // Get every line
   while (std::getline (ifsInputFile, strLine))
   {
   // Use std::stringstream to isolate words using operator >>
   std::stringstream ssWordsBuf (strLine);

   std::string strWord;
   while (ssWordsBuf >> strWord){
if(strWord.length() == 4){
// write to file
outfile<< " "<< "****" << " ";
}
else{
outfile << " "<< strWord << " ";
}
}

   }

   ifsInputFile.close ();
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote