Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Description You will read in an encoded message from a text file, then o

ID: 3705241 • Letter: P

Question

Problem Description

You will read in an encoded message from a text file, then output the decoded message to another text file.

Programming Exercise

Here is the encoded message –

Mrkq#6=49#Dpsolilhg#Eleoh#+DPS,#%Iru#Jrg#vr#^juhdwo|`#oryhg#dqg#ghduo|#sul}hg#wkh#zruog/#wkdw#Kh#^hyhq`#jdyh#Klv#^Rqh#dqg`#^d`rqo|#ehjrwwhq#Vrq/#vr#wkdw#zkrhyhu#eholhyhv#dqg#wuxvwv#lq#Klp#^dv#Vdylru`#vkdoo#qrw#shulvk/#exw#kdyh#hwhuqdo#olih1

Copy this text and save it to a text file.

Write a C++ program that does the following:

Creates a class called Paragraph. It will have one private member variable of type string.

Opens the text file and reads in the text and stores it in an instance of “Paragraph”.

Decode the message by subtracting 3 from the ASCII value for each character (For example, ‘M’ becomes ‘J’, and ‘#’ becomes a space character).

Store the decoded message in another instance of “Paragraph”.

Output the decoded message to another text file.

If this is done successfully, you will see an English, decoded message in the new text file.

Explanation / Answer

With File Handling:

#include <iostream>

#include <fstream>

#include <string.h>

using namespace std;
class Paragraph
{

char para[300];
char solve[300];


public:

void initial()
{
ifstream infile;

infile.open(“file.dat”);

infile>>para;

infile.cloase();

}

void decode()
{
int i=0;
for(i=0;i<strlen(para);i++)
{
solve[i]=para[i]-3;
}
solve[i+1]=' ';
cout<<”Your Decoded Message :”<<” ”<<solve;
}

void display()

{

ofstream outfile;

outfile.open(“ofile.dat”);

outfile<<solve;

}

};

int main()
{
Paragraph p;
p.initial();
p.decode();
p.display();
return 0;
}

Without File Handling:

#include <iostream>
#include <string.h>

using namespace std;
class Paragraph
{

char para[300];
char solve[300];


public:

void initial()
{
strcpy(para,"Mrkq#6=49#Dpsolilhg#Eleoh#+DPS,#%Iru#Jrg#vr#^juhdwo|`#oryhg#dqg#ghduo|#sul}hg#wkh#zruog/#wkdw#Kh#^hyhq`#jdyh#Klv#^Rqh#dqg`#^d`rqo|#ehjrwwhq#Vrq/#vr#wkdw#zkrhyhu#eholhyhv#dqg#wuxvwv#lq#Klp#^dv#Vdylru`#vkdoo#qrw#shulvk/#exw#kdyh#hwhuqdo#olih1");

}

void decode()
{
int i=0;
for(i=0;i<strlen(para);i++)
{
solve[i]=para[i]-3;
}
solve[i+1]=' ';
cout<<solve;
}
  
};

int main()
{
Paragraph p;
p.initial();
p.decode();

return 0;
}

Thanks & Regards..!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote