Let\'s try this again. I did get a partial answer earlier, but the expert missed
ID: 3682756 • Letter: L
Question
Let's try this again. I did get a partial answer earlier, but the expert missed the user inputting the filename.
Write a C++ program that asks the user for the name of an input file and translates the contents of that input file using ROT13. Your main function should be responsible for reading the input file and coordinating calls to a value-returning function named Rot13 that will do the translation for each character andWriteTranslatedCharacter that will write the translated character to a secondary file. The Rot13 function takes as input the character to be translated and returns the translated character. The second function namedWriteTranslatedCharacter will have two parameters, the translated character and a reference to an ifstream data type for a secondary file named "output.rot13", and write the translated character to this file.
If you don't mind, some explanation is appreciated. I need to know as I start diving deeper into this class. Thank you.
Explanation / Answer
c++ code:
#include <bits/stdc++.h>
using namespace std;
char Rot13(char c){
return c;
}
void WriteTranslatedCharacter(char c ,ofstream& outf){
outf<<c;
}
int main() {
//taking input from user
string f_name;
cout<<"Enter a file name: ";
cin>>f_name;
//input file stream
ifstream inf;
inf.open(f_name.c_str());
//output file stream
ofstream outf;
outf.open("output.rot13");
//reading file line by line
string s;
while(getline(inf,s)){
int l=s.length();
for(int i=0;i<l;i++){
WriteTranslatedCharacter(Rot13(s[i]),outf);
}
outf<<endl;
}
return 0;
}
You have not explained the Rot13 function , so I returned the same character. You have to change that.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.