Answer to Question #184808 in C++ for John

Question #184808

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.


Please follow all instructions


1
Expert's answer
2021-04-23T18:34:56-0400
#include <iostream>
#include <fstream>
using namespace std;
class Paragraph{
    string message;
    public:
    Paragraph(string s){
        message = s;
    }
    Paragraph decode(){
        string s = "";
        for(int i = 0; i < this->message.length(); i++){
            s += message[i] - 3;
        }
        return Paragraph(s);
    }
    string getText(){
        return this->message;    
    }
};
int main(){
    fstream Text;
    Text.open("encoded.txt", ios::in);
    if(!Text) cout<<"File Not Found!";
    else{
        string s;
        getline(Text, s);
        Text.close();
        Paragraph P1(s), P2 = P1.decode();
        Text.open("decoded.txt", ios::out | ios::trunc);
        Text<<P2.getText();
        Text.close();
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS