demonstrate the use of files to access data in secondary storage

C++ program that reads text from a file and decodes the file
by subtracting 5 from the ASCII value of each character.
Last edited on
ok I have worked on my program and here is what I have not sure how to fix it.
If someone could give me any help would be app.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>

using namespace std;

int main() 
{
    string line;
    int charIndex;
    string readline;
    fstream input;
    fstream output;

    input.open("code.txt", ios::in);

    output.open("plain.txt", ios::out);

    readLine = "";

    while (input.good())
	{
        input >> theline;

        if (readline ! "") 
		{
            
            charIndex > 0;

            while (charIndex) 

			{
                line +> (char);

				((int) readLine[charIndex] - 5);

                charIndex = charIndex + 1;
            }
            output << theline << endl;

            readLine = "";
        
    
    input.close();

    output.close();

    return 0;
}

1
2


Last edited on
#include <fstream>
here is what I have to do C++ program that reads text from a file and decodes the file
by subtracting 5 from the ASCII value of each character.
but I am having errors
and my assiment is past due anyone please help me on this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <fstream>
#include <string>

using namespace std;



int main()
{
	ifstream inputFile;
	const int SIZE = 135;
	char charHold;
	char fileName[SIZE];

	//output files
	ofstream outputFile("encoded.txt");


	ofstream outputFile("encoded.txt");

	cout << "Enter name of File: " ; //put plain.txt
	cin >> fileName;

	//input files
	inputFile.open(fileName);



	//test the file
	if(!inputFile)
	{
		cout << "Error: File " << fileName << " " << "can not find that name.";
		return 0;
	}

	inputFile.get(charHold);
	while (inputFile.good())
	{
		outputFile.put(static_cast<int>(charHold) + 5);
		inputFile.get(charHold);
		outputFile << charHold;
	}

	inputFile.close();
	outputFile.close();
	cout << "The encoded file is ready" ;

	return 0;
}


Here are my errors

1>------ Build started: Project: lab10 c++ rl, Configuration: Debug Win32 ------
1> lab10c++ rl.cpp
1>c:\users\rolena\documents\visual studio 2010\projects\lab10 c++ rl\lab10 c++ rl\lab10c++ rl.cpp(20): error C2374: 'outputFile' : redefinition; multiple initialization
1> c:\users\rolena\documents\visual studio 2010\projects\lab10 c++ rl\lab10 c++ rl\lab10c++ rl.cpp(17) : see declaration of 'outputFile'
1>c:\users\rolena\documents\visual studio 2010\projects\lab10 c++ rl\lab10 c++ rl\lab10c++ rl.cpp(42): error C2088: '<<' : illegal for class
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You declared the same ofstream object twice. It's pretty clear from the errors and simply looking at the code. As for that 3rd errors, I'm not sure on that one since I'm pretty sure I've used the << operator for file output myself before. What compiler are you using?
ok here is my c++ code and I will post my input file but it is not coming out right if someone could please help me figure out how to fix it my last chance to turn it in is tomorrow at midnight and I am close to failing this class please anyhelp would be great... :) :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	ifstream inputFile;
	const int SIZE = 135;
	char charHold;
	char fileName[SIZE];

	ofstream outputFile("encoded.txt");

	cout << "Enter name of File: " ; //put plain.txt
	cin >> fileName;

	//input files
	inputFile.open(fileName);

	//test the file
	if(!inputFile)
	{
		cout << "Error: File " << fileName << " " << "can not find that name.";
		return 0;
	}

	inputFile.get(charHold);
	while (inputFile.good())
		
	{
		if (charHold=='/n')
          outputFile.put ('/n');
		else
		outputFile.put(static_cast<int>(charHold) - 5);
		inputFile.get(charHold);
		
	}

	inputFile.close();
	outputFile.close();
	cout << "The encoded file is ready" ;


	return 0;
}


here is my input code

Ymnx%nx%f%xfruqj%nsuzy%knqj%ktw%HTXH%698;
fxxnlsrjsy%(653%^tzw%uwtlwfr%xmtzqi%jshtij%ymnx
knqj%g~%fiinsl%:%yt%ymj%FxHNN%{fqzj%tk%jfhm%hmfwfhyjw%ns%ny3
Ns%~tzw%jshtiji%knqj%ymj%knwxy%hmfwfhyjw%xmtzqi%gj%,^,3%Ymj%
qfxy%hmfwfhyjw%tk%ymj%knwxy%qnsj%xmtzqi%gj%,@,3
Ymj%jshtiji%knqj%xmtzqi%mf{j%=%qnsjx%tk%yj}y%ozxy%qnpj%ymnx%tsj1
gzy%|nqq%gj%zswjfifgqj3%Ymj%qfxy%hmfwfhyjw%tk%ymj%qfxy%qnsj%|nqq%
gj%f%,8,3


and here is what it looks like when encoded

This is a sample input file for COSC 1436assignment #10. Your program should encode thisfile by adding 5 to the AsCII value of each character in it.In your encoded file the first character should be 'Y'. The last character of the first line should be ';'.The encoded file should have 8 lines of text just like this one,but will be unreadable. The last character of the last line will be a '3'.

and here is what it should look like
This is a sample input file for COSC 1436
assignment #10. Your program should encode this
file by adding 5 to the AsCII value of each character in it.
In your encoded file the first character should be 'Y'. The
last character of the first line should be ';'.
The encoded file should have 8 lines of text just like this one,
but will be unreadable. The last character of the last line will
be a '3'.

it all runs on one line instead of on 8 lines Please someone help

Topic archived. No new replies allowed.