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!!!!!!!!!!!!!

You need to:

  1. Use code tags.
  2. Take whatever you professor gave you and turn it into your own words. We hsve no idea, for example, what Appendix 3 is, so don't refer to it.
  3. Tell us what the problem is. You're stuck, but where?
  4. Does it compile? Does it compile, but crash when you run it? Does it compile and run, but give bad results? What?

>> 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.

Way too vague. What is encrypted? What's the algorithm? Are the first six characters an encryption key to be used on the rest of the file. All you do is just add 10 to the ASCII values? The numbers 6 and 10 appear nowhere in your code.

I see nothing in the spec that asks you to change "C" to "C++". Why are you doing it?

If you are planning on changing all letters to lower case, you need to #include the cctype library and use it.

This is the spec that was given:

Below are the characters in the file: TextIn.txt

EBC;Iit_is a CaPital Mistake tO_theorize Before_one has DatA123.

The file is divided into 2 parts. The first 6 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

EBC;I it_is a CaPital Mistake tO_theorize Before_one has DatA123.

Fill in the following blanks with the correct ASCII value. Use Appendix 3 for a list of values.

ASCII value ASCII value +10

>   ___     ___
E   ___     ___
B   ___     ___
C   ___     ___
;   ___     ___
I   ___     ___

What characters will be written to txtOut.txt if this is the input?

It_is a CaPital Mistake tO_theorize Before_one has DatA123.

TextOut.txt

How many alphabetic characters in textOut.txt? ___________

How many asterisks in textOut.txt? ___________

The function in the program was the template we were given and had to adjust for the program. My revision is:

void add_plus_plus(ifstream& in_stream, ofstream& out_stream)
{
    char next;

    in_stream.get(next);
        while (! in_stream.eof( ))
    {
        if (next == 6)
            out_stream << next ;
        else
            out_stream.put(next);

        in_stream.get(next);    

    }
}

My problem is that I am not sure how to get and decode the first 6 characters in the data file and then adjust the function to read just the remaining characters and not the first 6. When I checked the output file it has just copied the data file over with the first 6 characters still there. That is where I am stuck and can't go forward because without getting this function correct first.

Code tags. Put them around your code.

[code]

// code goes here

[/code]

Two completely separate parts. Looks like the first part is a paper and pencil exercise, though you could use the program too. Either read them in and do something with them or just read them in and throw them away. Use a plain old loop.

// Part 1
for(int i = 0; i < 6; i++)
{
    in_stream.get(next);
    // do something with next if you want.  Add 10 and display or whatever.
}

// Now the 6 characters are out of the way, so go on to part 2

Thank you for your help. I was able to figure out the program WITH THAT HELP

how would they return that function back to main?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.