If you have any doubts, please give me comment...
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
string read_file(string filename)
{
ifstream in;
in.open(filename.c_str());
string str = "", inp;
if (in.is_open())
{
while (!in.eof())
{
getline(in, inp);
str += inp + "\n";
}
return str;
}
else
{
cout << "Error opening file" << endl;
exit(1);
}
}
string encode(string str)
{
int i, len = str.length() - 1;
string enc_str = str;
for (i = 0; i < len; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
if (str[i] + 13 > 'Z')
enc_str[i] = 'A' + ((str[i] + 13 - 'Z') % 26) - 1;
else
enc_str[i] = str[i] + 13;
}
else if (str[i] >= 'a' && str[i] <= 'z')
{
if (str[i] + 13 > 'z')
enc_str[i] = 'a' + ((str[i] + 13 - 'z') % 26) - 1;
else
enc_str[i] = str[i] + 13;
}
}
return enc_str;
}
string decode(string str)
{
int i, len = str.length() - 1;
string dec_str = str;
for (i = 0; i < len; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
if (str[i] - 13 < 'A')
{
dec_str[i] = 'Z' - (('A' - (str[i] - 13)) % 26) + 1;
}
else
dec_str[i] = str[i] - 13;
}
else if (str[i] >= 'a' && str[i] <= 'z')
{
if (str[i] - 13 < 'a')
{
dec_str[i] = 'z' - (('a' - (str[i] - 13)) % 26) + 1;
}
else
dec_str[i] = str[i] - 13;
}
}
return dec_str;
}
void write_file(string str, string filename)
{
ofstream out(filename.c_str());
out << str;
cout << "successfully write into "<<filename << endl;
}
int main()
{
string filename, str;
cout << "Enter filename: ";
cin >> filename;
str = read_file(filename);
string enc_str = encode(str);
write_file(enc_str, "out_encode.txt");
str = read_file("out_encode.txt");
string dec_str = decode(str);
write_file(dec_str, "out_decode.txt");
return 0;
}

The task at hand is to create a C++ program (without using any templates) to encode...