K
kristiek
ive been trying to write a program for 2 weeks now, and im still lost!
it's due tomorrow!!!! ANY help from anyone, would be soooooo
appreciated...i will owe you my life!!! here's the deal: I have to
write a program that encodes the text in a data file using a character
array named key that contains 26 characters. This key is read from the
keyboard; the first letter contains the character that is to replace
the letter a in the data file, the second letter contains the letter
that is to replace the letter b in the data file, and so on. Assume
that all punctuation is to be replaced by spaces. Check to be sure
that the key does not map two different characters to the same one
during the encoding.
Requirement:
1.Read data from keyboard to key array. And give the user the hint
that EACH
ELEMENT IN THE key array MUST BE DIFFERENT FROM EACH OTHER.
2.If the character in the data file is between ‘a' and ‘z', replace it
according
to key array. If the character in the data file is a punctuation,
replace it by
space. Otherwise, (such as capital letters) the character in the data
file stays same.
So that's the assignment...and even tho i am sure all you master
programmers out there are going to laugh at what i have, i am going to
post my program thus far...please help!!!!!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream file1 ("infile.txt");
ofstream file2;
int main ()
{
char * key;
key = new char[26]; //creating an array, known as "key"
for (int i=0; i<26; i++)
cout << "Enter the code you wish to use for the key. The first
character
you type will replace the letter 'a', the second will replace 'b', and
so on. Be
careful not to repeat the same character twice." << endl;
cin >> key ;
char * text;
text = new char [100]; //creates an array to hold the text from the
input file
int i=0; // creates an index counter so the array can be read into
file1.open (filename.c_str()); //reading in from the file
if (file1.fail()) //checking to make sure the file opens correctly
{
cout << "Error opening input file. Please check and try again."
<< endl;
}
else
{
while (! file1.eof())
{
text=file1.get(c);
}
file1.close();
}
return0;
}
it's due tomorrow!!!! ANY help from anyone, would be soooooo
appreciated...i will owe you my life!!! here's the deal: I have to
write a program that encodes the text in a data file using a character
array named key that contains 26 characters. This key is read from the
keyboard; the first letter contains the character that is to replace
the letter a in the data file, the second letter contains the letter
that is to replace the letter b in the data file, and so on. Assume
that all punctuation is to be replaced by spaces. Check to be sure
that the key does not map two different characters to the same one
during the encoding.
Requirement:
1.Read data from keyboard to key array. And give the user the hint
that EACH
ELEMENT IN THE key array MUST BE DIFFERENT FROM EACH OTHER.
2.If the character in the data file is between ‘a' and ‘z', replace it
according
to key array. If the character in the data file is a punctuation,
replace it by
space. Otherwise, (such as capital letters) the character in the data
file stays same.
So that's the assignment...and even tho i am sure all you master
programmers out there are going to laugh at what i have, i am going to
post my program thus far...please help!!!!!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream file1 ("infile.txt");
ofstream file2;
int main ()
{
char * key;
key = new char[26]; //creating an array, known as "key"
for (int i=0; i<26; i++)
cout << "Enter the code you wish to use for the key. The first
character
you type will replace the letter 'a', the second will replace 'b', and
so on. Be
careful not to repeat the same character twice." << endl;
cin >> key ;
char * text;
text = new char [100]; //creates an array to hold the text from the
input file
int i=0; // creates an index counter so the array can be read into
file1.open (filename.c_str()); //reading in from the file
if (file1.fail()) //checking to make sure the file opens correctly
{
cout << "Error opening input file. Please check and try again."
<< endl;
}
else
{
while (! file1.eof())
{
text=file1.get(c);
}
file1.close();
}
return0;
}