Question: Project Four Text File Processing Write a program to decipher a code and process a set of characters in a text file. You will see
Project Four
Text File Processing
Write a program to decipher a code and process a set of characters in a text file.
You will see there are 8 encrypted characters at the beginning of the file. The encryption is based on the ASCII code (check Appendix 3). The value 10 has been subtracted from the ASCII value of each of the first 8 characters.
After opening the files, write a function with a for loop that reads and decrypts each character. The loop should stop after the 8 characters are displayed on the screen in a readable format. You should recognize the name.
The first 8 characters should NOT be written to the output file and are not part of the totals displayed.
Write a second function using the add_plus_plus function in Display 6.8 as a guide to process the remaining characters in the file, creating the file: textOut.txt
Make these changes before writing to the output file
Change Insanity to all uppercase (use a for loop before the while loop).
Use a nested if for the following changes:
Change dashes (-) to spaces.
Change all the remaining letters to lowercase.
Change digits to #.
Display these totals on the screen with appropriate labels. Do not write these totals to the output file.
Count all the dashes.
Count all the digits.
Change the name of the function from add_plus_plus to something more appropriate.
Open and print the file TextProcPlanning.doc. Determine the correct output using this form before you write the code.
Purpose of this project
Develop C++ program with the following new features:
Character I/O
Pre-defined character functions
Cast operator
Counters (Chapter Two and Six Notes page)
Advice from the Instructor:
Display 6.8 is a good example for this project.
Use pre-defined character functions when available.
Check out the Pitfall on page 358.
Be sure to pause the screen if an error occurs when opening the file.
Read the input file only once.
For pc users: Use the root directory of your disk to store the files to avoid problems with accessing the files. When you open a file, note the double slashes in the following example so that the compiler doesnt interpret the backslash as an escape character.
fin.open(c:\\textIn.txt);
You may not be able to use the root directory of the C drive with Windows 8 so you may have to create a folder so the open would look like this:
fin.open(c:\\folder\\textIn.txt);
*folder is any folder name.
For mac users: Use the forward slash to separate directories instead of the back slash. If the file is saved on your desktop then you would enter something like:
fin.open (/Users/Name/Desktop/textIn.txt);
The directories, name, and file name are case sensitive.
If you use a file in a function that has been opened in main, you need to pass a file reference to the function. Display 6.8 shows an example of the necessary syntax.
Remember to use the Class Standards when displaying the output.
Testing:
When you first test this project, just read the file without processing the characters to make sure the file processing commands are correct.
I have attached 06-08.cpp (Display 6.8) so you can use this code as the base for this project. Just change the file names and run the code see what happens. This will test your file processing commands.
After the file commands are correct, go back and change the code to meet the project requirements.
In the C++ editor, File/Open textIn.txt so you can make sure that you're working with the correct data. After you run the program once:
File/Open textOut.txt so you can see the output file. As you test, you will get a message about the output file changing and do you want to reload. Click Yes so you can see your output file as it changes.
Below are the characters in the file: TextIn.txt
;_dij[_dInSaniTy:-doing the Same thing Over-and over AGAIN-and expEcting diFferent-results123.
The file is divided into 2 parts. The first 8 characters are the code you need to decipher. The second part is the text to process and write to the output file.
Part I Part II
;_dij[_dInSaniTy:-doing the Same thing Over-and over AGAIN-and expEcting diFferent-results123.
Fill in the following blanks with the correct ASCII value. Use Appendix 3 for a list of values.
ASCII value ASCII value +10
; ___ ___
_ ___ ___
d ___ ___
i ___ ___
j ___ ___
[ ___ ___
_ ___ ___
d ___ ___
What characters will be written to txtOut.txt if this is the input?
InSaniTy:-doing the Same thing Over-and over AGAIN-and expEcting diFferent-results123.
TextOut.txt
Total digits in the file = ????
Total dashes in the file = ????
//DISPLAY 6.8 Editing a File of Text
//Program to create a file called cplusad.dat that is identical to the file
//cad.dat, except that all occurrences of 'C' are replaced by "C++".
//Assumes that the uppercase letter 'C' does not occur in cad.dat except
//as the name of the C programming language.
#include
#include
#include
using namespace std;
void add_plus_plus(ifstream& in_stream, ofstream& out_stream);
int main( )
{
ifstream fin;
ofstream fout;
cout
fin.open("g:\\cad.dat");
if (fin.fail( ))
{
cout
exit(1);
}
fout.open("g:\\cplusad.dat");
if (fout.fail( ))
{
cout
exit(1);
}
add_plus_plus(fin, fout);
fin.close( );
fout.close( );
cout
system("pause");
return 0;
}
void add_plus_plus(ifstream& in_stream, ofstream& out_stream)
{
char next;
in_stream.get(next);
while (! in_stream.eof( ))
{
if (next == 'C')
out_stream
else
out_stream.put(next);
in_stream.get(next);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
