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

Write a program that will correct a C++ program that has errors in which operato

ID: 3665832 • Letter: W

Question

Write a program that will correct a C++ program that has errors in which operator, << or >>, it uses with cin and cout. The program replaces each (incorrect) occurrence of

with the corrected version

and each (incorrect) occurrence of

with the corrected version

Allow for the possibility that there may be any number of whitespace characters (one or more) between cin and << and between cout and >>. The replacement corrected version has only one blank between the cin or cout and the following operator.

Your program should get the source filename as an input from the user. The corrected version should be output to a file with name“corrected.txt” and it should also be displayed on the terminal. That means output of your program (after getting the filename) should be exactly same as the contents of the file “corrected.txt”. Your program should define a function that is called with the input- and output-file streams as arguments.

A session should look like the following example (including whitespace and formatting):

File “corrected.txt” consists of the above output except first two lines.

Explanation / Answer

// error: missing ')' in parameter list for main
int main ( {
// error: used colon, not a semicolon after endl
std::cout << "Read each file." << std::endl:
// error: missing quotes around string literal
std::cout << Update master. << std::endl;
// ok: no errors on this line
std::cout << "Write new master." <<std::endl;
// error: missing ';' on return statement
return 0
}

#include <iostream>
int main()
{
int v1, v2;
std::cin >> v >> v2; // error: uses " v "not" v1"
// cout not defined, should be std::cout
cout << v1 + v2 << std::endl;
return 0;
}

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