Question: 2 Enumeration Data Types Reformat is the shell of a program designed to read characters and process them in the following way: Lowercase character Converts

2 Enumeration Data Types
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
#include
#include
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 to dataOut
}
dataIn.get(character);
}
return 0;
}
//*************************************************
CharType KindOfChar(char character)
{
if (isupper(character))
return // TO BE FILLED IN
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
}
Exercise 1:
You are to fill in the code of function KindOfChar and the switch statement in the body of function main.
Run your program. List below the last three lines of output written on file DataOut.
(Note: the functions isupper, islower, isdigit are provided by the cctype library.
isupper returns true if the parameter character is an upper case letter.
islower returns true if the parameter character is a lower case letter.
isdigit returns true if the parameter character is a decimal digit.
You can use the toupper function also provided by the cctype library to convert a lower case letter to
upper case.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!