Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [100pts] Write a program that reads The program crosses out every character c from the input words. A sample run of the program is shown below:
    ~/$ ./a.out
    Letter to cross out: i
    How many words? 10
    dry
    spicy
    spotted
    minute
    hateful
    magic
    support
    thick
    pretty
    frightened
    dry --> dry
    spicy --> sp*cy
    spotted --> spotted
    minute --> m*nute
    hateful --> hateful
    magic --> mag*c
    support --> support
    thick --> th*ck
    pretty --> pretty
    frightened --> fr*ghtened
    
    I wrote part of the code for you. Declare and define the necessary functions so that the code will function correctly.
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() {
      // receive a letter to cross out
      char c;
      cout << "Letter to cross out: ";
      cin >> c; 
    
      // how many words to read?
      int n;
      cout << "How many words? ";
      cin >> n;
    
      // read the actual n words from the input
      string* arrWords = new string[n];
      for( int i=0; i < n; i++ )
        cin >> arrWords[i];
    
      // ***** DECLARE AND DEFINE: cloneArray
      // clone the array arrWords to arrCrossout
      // arrCrossout is used right below
      string* arrCrossout = cloneArray(arrWords, n);
    
      // ***** DECLARE AND DEFINE: crossOut
      // Crossout!
      crossOut(c, arrCrossout, n);
    
      // Print out the results
      for( int i=0; i < n; i++ )
        cout << arrWords[i] << " --> " << arrCrossout[i] << endl;
    
      return 0;
    }
    

    Hint

    We already know how to cross out characters of a single word (refer to the Hangman lab).
    I would create two functions crossOut (one for a single word from the lab, the other for an array of words) by using the function overloading, but it's just me.

    Turn In your source code and a screen capture of your program running on above example.