I need to write a program to decipher a code and process a set of characters in a text file.
this is the text file:
EBC;Iit_is a CaPital Mistake tO_theorize Before_one has DatA123.
There are 6 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 6 characters.
After opening the files, I have to write a function with a for loop that reads and decrypts each character. The loop should stop after the 6 characters are displayed in a readable format. You should recognize the name – he is a famous literary character.
The first 6 characters should not be written to the output file and are not part of the totals displayed.
Then write a second function to process the remaining characters in the file, creating the file: textOut.txt
Before writing to the output file, I have to:
- Change underscores (_) to spaces.
- Change all characters to lowercase.
- Change digits to * (asterisks).
Display these two totals on the screen with appropriate labels (do not write the totals to the file) after processing the file:
- Count all the numbers converted to * (asterisks).
- Count all alphabetic characters written to the output file.
The code that I have so far is:
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
void add_plus_plus(ifstream& in_stream, ofstream& out_stream);
int main( )
{
ifstream fin;
ofstream fout;
cout << "Begin editing files.\n";
fin.open("c:\\Users\\LADYHVB\\Documents\\textIn.txt");
if (fin.fail( ))
{
cout << "Input file opening failed.\n";
exit(1);
}
fout.open("c:\\Users\\LADYHVB\\Documents\\textOut.txt");
if (fout.fail( ))
{
cout << "Output file opening failed.\n";
exit(1);
}
add_plus_plus(fin, fout);
fin.close( );
fout.close( );
cout << "End of editing files.\n";
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 << "C++";
else
out_stream << "";
in_stream.get(next);
}
}
I am totally lost on what I am doing wrong. I have been trying to work this problem for a week now. PLEASE HELP!!!!!!!!!!!!!