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

#include<iostream> #include<fstream> #include<stdlib.h> #include<string> using n

ID: 3886452 • Letter: #

Question

#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string>

using namespace std;

void readFile(string inputFileName, string *words, int num){
      ifstream fin;
      char *p = &inputFileName[0];

      fin.open(p);

      for (int i = 0; i<num; i++){
          getline(fin,words[i]);
      }
      fin.close();

}


void writeFile(string outputFileName, string *words, int num){
      ofstream fout;
      char *p;

      p = &outputFileName[0];
      fout.open(p);
      for (int i = 0; i<num; i++){
          fout << words[i] << endl;
      }
      fout.close();

}


int main(int argc, char **argv){

   //Check correct number of arguments
   if (argc != 5) {
      cout << "Error" << endl;
      return 0;
   }  

   //Handling cmd line args
   //YOU MUST INITYIALIZE THEIR VALUES
   string inputFileName = argv[1];
   string outputFileName = argv[2];
   int numberOfWords = atoi(argv[3]);
   char *lettersToReplace;
   char *p;
   int found;

   //Checking valid input
   if (numberOfWords <= 0) {
       cout << "Error" << endl;
       return 0;
   }
   string words[numberOfWords];
   readFile(inputFileName, words,numberOfWords);  
     
   for (int i = 0; i<numberOfWords; i++){
          p = argv[4];
          found = 0;
         
          for (int j = 0; *p != ''; j++){
              if (words[i][0] == *p)
                 found = 1;
              p++;      
          }
          if (found == 1)
              words[i] = "---";
    }
    writeFile(outputFileName, words,numberOfWords);
               
   return 0;
}

Here is the main function that you must use. You may not add or remove parameters or change the names of the variables. You must initialize the values of the variables.: int main (int argc, char argv)t //Check correct number of argument:s if ( argc != 5 ) { cout

Explanation / Answer

Hi, here is the replaceWord function, you need,

void replace(string &word,char toReplaceInword)

{

if(word[0]==toReplaceInword) //check if it starts with given char

word="----"; //set the word to 4 dashes

}
Thumbs up if this was helpful, otherwise let me know in comments.