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

Reformat is the shell of a program designed to read characters and process them

ID: 3542456 • Letter: R

Question

Reformat is the shell of a program designed to read characters and process them in

the following way.


Lowercase character                Converts to uppercase and writes the character

Uppercase character                Writes the character

Digit                                        Writes the digit

Blank                                      Writes a blank

Newline                                   Writes newline

Any other character                  Does nothing


// Program Reformat reads characters from file DataIn and

// writes them to DataOut with the following changes:             

//    all letters are converted to uppercase, digits are

//    unchanged, and all other characters except blanks and         

//    newline markers are removed.                                       


#include <iostream>

#include <cctype>

#include <fstream>

using namespace std;


enum CharType {LO_CASE, UP_CASE, DIGIT, BLANK_NEWLINE, OTHER};


CharType  KindOfChar(char);

// Post: character has been converted to the corresponding            

//       constant in the enumeration type CharType.           


int main ()

{

  ifstream  dataIn;

  ofstream  dataOut;

  char  character;

  dataIn.open("reformat.dat");

  dataOut.open("dataOut.dat");

    

  dataIn.get(character);    // Priming read

  while (dataIn)

  {

    switch (KindOfChar(character))

    {       

      // FILL IN THE Code to output the correct character

case LO_CASE:

dataOut << char(character - 32);

break;

case UP_CASE:

// what to do here

//More cases follow

    }

    dataIn.get(character);

  }

  return 0;

}


                                                            

//*************************************************         

                                                            

CharType  KindOfChar(char  character)     

{

  if (isupper(character))              

    return UP_CASE;

  else if (islower(character))

    return  // TO BE FILLED IN

  else if (isdigit(character))

    return  // TO BE FILLED IN                                                   

  else if (character == ' ' || character == ' ')

    return  // TO BE FILLED IN               

  else

    return  // TO BE FILLED IN

}


=======================================================================================


FILE :  reformat.dat contains


lowercase characters   UPPERCASE CHARACTERS

ABCDEF  ....

abcdeft;;;;;

12345  6789

: < > ? " :

=======================================================================================






Explanation / Answer

// Program Reformat reads characters from file DataIn and
// writes them to DataOut with the following changes:
// all letters are converted to uppercase, digits are
// unchanged, and all other characters except blanks and
// newline markers are removed.
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
enum CharType {LO_CASE, UP_CASE, DIGIT, BLANK_NEWLINE, OTHER};
CharType KindOfChar(char);
// Post: character has been converted to the corresponding
// constant in the enumeration type CharType.
int main ()
{
ifstream dataIn;
ofstream dataOut;
char character;
dataIn.open("reformat.dat");
dataOut.open("dataOut.dat");
if(!dataIn)
{
    cout << "Unable to open file. so exiting from program" << endl;
    return 0;
}
dataIn.get(character); // Priming read
while (dataIn)
{
switch (KindOfChar(character))
{
// FILL IN THE Code to output the correct character
case LO_CASE:
dataOut << char(character - 32);
break;
case UP_CASE:
case DIGIT:
case BLANK_NEWLINE:
dataOut <<character;break;
default:break;
}
dataIn.get(character);
}
dataIn.close();
dataOut.close();
return 0;
}
//*************************************************
CharType KindOfChar(char character)
{
if (isupper(character))
return UP_CASE;
else if (islower(character))
return LO_CASE;
else if (isdigit(character))
return DIGIT;
else if (character == ' ' || character == ' ')
return BLANK_NEWLINE;
else
return OTHER;
}


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