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

Can you convert this to pseudocode? #include <fstream> #include <cstdlib> using

ID: 3713434 • Letter: C

Question

Can you convert this to pseudocode?

#include <fstream>
#include <cstdlib>
using namespace std;

void mailMerge(ifstream& input, ofstream& output);

void mailMerge(ifstream& input, ofstream& output)
{
cout << "Inside mailMerge " << endl;
output << "Inside mail Merge - this is the write to a file line "
         << endl;
}

void mailMerge(ifstream& input, ofstream& output)
{
char x;
char x2, x3;
char seenName = 0;
while(input.get(x))
{
    char firstName[21], lastName[21];
    if ('#' == x)
    {
      input.get(x2);
      if ('N' == x2)
      {
        input.get(x3);
        if ('#' == x3)
        {
          if (!seenName)
          {
             seenName = 1;
            cout << "Please enter a first name"
                 << " and a last name" << endl;
            cin >> firstName >> lastName;
            output << firstName << " "
                   << lastName;
          }
          else
            output << firstName;
        }
          else
            input.putback(x3);
      }
        else
          input.putback(x2);
    }
    else
      output << x;
}
}
int main()
{
char bodyName[21];
cout << "Enter the name of a file containing the letter body. "
       << " -- 20 characters max " << endl;
cin >> bodyName;
ifstream body;
body.open(bodyName);
if(!body)
{
    cout << "Cannot open file " << bodyName
         << " Aborting!" << endl;
    exit(1);
}
cout << "Enter the name of a file for the finished letter. "
       << "-- 20 characters max " << endl;
char letterName[21];
cin >> letterName;
ofstream letter;
letter.open(letterName);
if(!letter)
{
    cout << "Cannot open file " << letterName
         << " Aborting!" << endl;
    exit(1);
}
mailMerge(body, letter);
return 0;
}

Explanation / Answer

mailMerge(instream,outstream)

input x

IF x is '#'

input x2

if x2 is 'N'

input x3

if seenName is 0

set seenName to 1

input firstname and lastname

end if

else

output firstName

end else

putback x3

end else

putback x2

end else

output x

end else

end mailMerge

Main

input bodyName

open file bodyName

input letterName

open output file letterName

call mailMerge

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