Study the following program carefully. This program is intended to take a text f
ID: 3632595 • Letter: S
Question
Study the following program carefully. This program is intended to take a text file and convert upper-case characters to lower-case and vice versa. Punctuation should not be affected. In the input text, a ' - ' (dash) indicates a space and a ' / ' (slash) indicates the end of the line. The character ' * ' is the sentinel value used to indicate end-of-file. This program will use a function called SwitchCase( ) . The declaration for SwitchCase and pre- and post-conditions are given in the program.#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
char SwitchCase(char);
//Program name: ViceVersa
char c;
fstream Infile;
int main(void)
{
Infile.open("a:\inlab83.txt", ios::in);
Infile>>c;
while (c != '*')
{
while (c != '/')
{
if (c == '-')
cout<<' ';
else
if (((c>='A')&&(c<='Z'))||((c>='a')&&(c<= z')))
cout<<SwitchCase(c);
else
cout<<c;
Infile>>c;
} // not end of line
cout<<endl;
Infile>>c;
} // not end of file
Infile.close();
cin.get(); cin.get();
return 0;
} // ViceVersa
char SwitchCase (char Target)
/* Pre-condition: Target is a letter.
Post-condition: The value returned is Target switched from
upper-case to lower-case or vice versa. */
{
} // SwitchCase
Activity 3.2: Add a new cpp file to Lab10 project called Lab10Tsk3.cpp and copy the program ViceVersa in Activity 3.1 to Lab10Tsk3.cpp. Then modify the program ViceVersa by completing the code body for SwitchCase( ). Be careful that SwitchCase( )satisfies the pre- and post-conditions. As you write the function body, remember you can assume that the preconditions will be true as the function executes. Any program that uses this function should be careful to only use the function in the way described by the pre- and post-conditions. Create a text file called InLab103.txt and test the modified program with the input file that you just created.
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
char SwitchCase(char);
//Program name: ViceVersa
char c;
fstream Infile;
int main(void)
{
//Infile.open("a:\inlab83.txt", ios::in);
Infile.open("input.txt", ios::in);
Infile>>c;
while (c != '*')
{while (c != '/')
{if (c == '-')
cout<<' ';
else
if (((c>='A')&&(c<='Z'))||((c>='a')&&(c<= 'z')))
cout<<SwitchCase(c);
else
cout<<c;
Infile>>c;
} // not end of line
cout<<endl;
Infile>>c;
}
// not end of file
Infile.close();
cin.get(); cin.get();
return 0;
} // ViceVersa
char SwitchCase (char Target)
/* Pre-condition: Target is a letter.
Post-condition: The value returned is Target switched from
upper-case to lower-case or vice versa. */
{if(isupper(Target))
return tolower(Target);
else
return toupper(Target);
} // SwitchCase