Question

In: Computer Science

hi everyone.i have to perform rot13 and program should also print missing command if there is...

hi everyone.i have to perform rot13 and program should also print missing command if there is no command or arguments and bad argument.it should also print file can not open if there if no file.i am very confuse,what should i do.here is my coding,please tell me if i am missing something.

#include<iostream>
#include<fstream>
#include<string>

using namespace std;


char Rot13(char to_be_translated)
{
if(to_be_translated>='A' && to_be_translated<='Z')
{
return (to_be_translated-'A'+13)%26+'A';
}
else if(to_be_translated>='a' && to_be_translated<='z')
{
return (to_be_translated-'a'+13)%26+'a';
}
return to_be_translated;
}

void WriteTranslatedCharacter(char translated_character, ofstream& output)
{
output << translated_character;
}

int main(int argc,char*argv[])
{
string input_file;

cout <<"Enter the name of input file:";
cin >> input_file;
cout << endl;

ifstream infile(input_file.c_str());
ofstream outfile("output.rot13");

if(!infile)
{
cout <<"Unable to open file" << endl;
return 0;
}

char char_from_file = infile.get();;
while(!infile.eof())
{
WriteTranslatedCharacter(Rot13(char_from_file), outfile);
char_from_file = infile.get();
}

infile.close();
outfile.close();
return 0;
}

Solutions

Expert Solution

//Modified C++ program

#include<iostream>
#include<fstream>
#include<string>

using namespace std;


char Rot13(char to_be_translated)
{
if(to_be_translated>='A' && to_be_translated<='Z')
{
return (to_be_translated-'A'+13)%26+'A';
}
else if(to_be_translated>='a' && to_be_translated<='z')
{
return (to_be_translated-'a'+13)%26+'a';
}
return to_be_translated;
}

void WriteTranslatedCharacter(char translated_character, ofstream& output)
{
translated_character = Rot13(translated_character);
output << translated_character;
}

int main(int argc,char*argv[])
{
if(argc==1)
cout<<"No Extra Command Line Argument Passed Other Than Program Name\n";
string input_file;

cout <<"Enter the name of input file:";
cin >> input_file;
cout << endl;

ifstream infile(input_file.c_str());
ofstream outfile("output.txt");

if(!infile)
{
cout <<"Unable to open input file" << endl;
return 0;
}
if(!outfile)
{
cout <<"Unable to open output file" << endl;
return 0;
}

char char_from_file = infile.get();
while(!infile.eof())
{
WriteTranslatedCharacter(char_from_file, outfile);
char_from_file = infile.get();
}

infile.close();
outfile.close();
return 0;
}


Related Solutions

Write a perl program that replicates the actions of a pez dispenser. The program should print...
Write a perl program that replicates the actions of a pez dispenser. The program should print out the contents of the dispenser showing that it is empty, prompt a user for 10 pez candy flavors/colors, print out the contents of the dispenser showing that it is full, dispense the candies one at a time, and then print out the contents of the dispenser showing that it is empty. The dispenser should only take in 10 candies and should load and...
USING a LOOP for C++ In this lab the completed program should print the numbers 0...
USING a LOOP for C++ In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and by 10....
Write a program, circleref.cpp, that inputs a double radius of circle. It should print, given this...
Write a program, circleref.cpp, that inputs a double radius of circle. It should print, given this radius, the circumference of the circle, the area of the circle, the surface area of a sphere with that radius and the area of a sphere with that radius. Each of its computation functions returns its answers in call by reference parameters. Here are the formulas for computation: Circumference = 2 • π • r Circle Area = π • r2 Sphere Surface Area...
The program should be able to do the following: In Java accepts one command line parameter....
The program should be able to do the following: In Java accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers...
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command...
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command that would find all lines that have an email address and place a label email = before the line in the file longfile output will multiple lines similar to this one : using a good awk command the output would be something like this email = From: "Linder, Jann/WDC" <[email protected]> email = To: Mr Arlington Hewes <[email protected]> email = > From: Mr Arlington Hewes...
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
You have to write a program that will read an array from a file and print...
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first...
A column in your data is missing a value in one row. Which command fills this...
A column in your data is missing a value in one row. Which command fills this missing data point with the value before it? Select an answer: df.fillna(method='bfill') df.fillna(0) df.fillna(method='linear') df.fillna(method='ffill')
Create a python program that will: prompt a user for a command Command get_data Level 1:...
Create a python program that will: prompt a user for a command Command get_data Level 1: Take one of the commands my_max my_min my_range my_sum mean median mode fib factorize prime Requirements: Your commands should be case-insensitive You should use python lists to store data You should NOT use built-in python math functions, or math libraries to compute these values Tips: Write one function that will convert a string with comma-separated numbers into a python list with the numbers. You...
------------------ International Economics --------------------- Hi there, I have needed Solution Of this Question and It should...
------------------ International Economics --------------------- Hi there, I have needed Solution Of this Question and It should be typing answer. * What are the reasons why a country uses direct or indirect quotation? ------------------------ Don't Copy From Google ------------------------------------
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT