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

This should be solved in the operators.cpp file. Write a program that will corre

ID: 3697061 • Letter: T

Question

This should be solved in the operators.cpp file. 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 cin << with the corrected version cin >> and each (incorrect) occurrence of cout >> with the corrected version cout << Allow for the possibility that there may be any number of blank space characters (zero or more) between cin and << and between cout and >> in the source input. The replacement corrected version should have only one blank space between the cin or cout and the following operator. A blank space is the space you get from pressing a space bar (ASCII 32). All other parts of the program should be left untouched. For this assignment, you are allowed to assume the following for our input test cases: cin, cout, <<, and >> do never appear in the input file as part of string constants; cin and cout statements are written in its own single line; cin and cout statements do not contain any expressions in which contains any of characters < or >, except those which appear in the operators << and >>; and cin and cout statements may (only) be preceded with some whitespaces of any kind, not just blank spaces. Use isspace function in the library cctype to check for these whitespaces. They should be preserved in the output corrected source file. Your program should get the source file name 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 file name) 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. Suppose that in a session, the file “original.txt” contains the following text. #include using namespace std; int main(){ cout >> "Hello!"; return 0; } The execution of the program should look like the following (including whitespace and formatting): Enter filename: original.txt #include using namespace std; int main(){ cout << "Hello!"; return 0; } File “corrected.txt” consists of the above output except first two lines.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
void Output_Data(ifstream &input, ofstream& output);


int main()
{
    ifstream input;
    ofstream output;
    input.open("original.txt");
    output.open("corrected.txt");
  
    if(input.fail( ))
{
     cout<<"Input file is missing"<<endl;
     exit(1);
}

   Output_Data(input,output);
    input.close();
    output.close();

    return 0;
}

void Output_Data(ifstream &input, ofstream& output)


        char next,letter1[4];


        input.get(next);
        while (! input.eof())
            {

                letter1<<next;
                if(letter1=='cin')
                {
                   output<<"cout<<";
                }
                else
                {
                    output<<next;
                }
                input.get(next);

            }
        }

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