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

The question was: QuestionDetails: I have a long program to write, but am stuck

ID: 3619307 • Letter: T

Question

The question was:

QuestionDetails: I have a long program to write, but am stuck on a smallportion.

1. Get a source file name from the user
and verify that the file
exists. If not, an appropriate error message should be displayedand
the program should terminate. (got thispart)



2. Check to see if new_<filename> already exists (where
<filename> is the filename entered by the user). If itdoes
already exist, confirm that it is ok to overwrite it
before proceeding. If the user's response to the confirmationrequest
is negative, terminate the program. (got thispart)



3. Read the source file from <filename> and copy it to
new_<filename>. As it is being copied, make the followingchanges:



  1. Convert all tab characters to double spaces.
  2. Whenever a left brace ("{") is encountered: (This is the part, if someone can give me a sample insertion,I would appreciate it. I don't need the answer to the homeworkassignment, just an example of how to get this next part, then Ithink it would come together.)



    1. Add 2 to the indentation count (initially zero)
    2. If the brace is not the last character on the line, inserta
      newline immediately after the brace.

  3. Whenever a right brace ("}") is encountered:

    1. Subtract 2 from the indentation count.
    2. If the brace is not the first character on the line, inserta
      newline immediately before the brace.

  4. Change the number of blank spaces at the front of each line tobe
    consistent with the indentation count. The easiest way to do thisis to
    delete all blank spaces (using a loop) and then insert thecorrect
    number of spaces (indentation count). There are string functionsthat
    will simplify the coding for these actions. (maybe an example of this too.)




    Correct indentation for program comments, for braces embeddedwithin
    comments or strings, and for continuation lines is not required,though
    you may
    attempt to incorporate these into your program as well if you'dlike a
    bit more of a challenge.





Hints:

The input can be processed either line-by-line orbyte-by-byte.
In either
case, use a single loop to process the input stream.

The following statement returns the next character fromthe
input file, without removing it from the input buffer:

char next =
cin.peek();

This is what I have so far, can you help, the deeper I get the morelost I get. What am I doing wrong?

#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main() {
string inFileName, outFileName, inLine, textLine;
char nextCharacter;
ifstream inFile;
ofstream outFile;
int count = 0;
   
cout << "Enter the input file name: ";
cin >> inFileName;

inFile.open(inFileName.c_str());
if (inFile.fail()) {
    cout << "The input file (" <<inFileName << ") can not be opened." << endl;
    system("pause.exe"); // wait for user to pressRETURN
   return 0;
     }

while(!inFile.eof()) {
    char inChar = inFile.get();
    if (!inFile.eof() && inChar == 10) {
      count++;
    }
}
   while (count < textLine.length () &&(!EOF))
        nextCharacter =textLine('{',0);
        if (nextCharacter >=0)
        {
           indentCount = indentCount + 2;
           cout << "Indention Count" << indentCount <<endl;
           count++;
         }
        else
    // if brace is not last character, insertnewline after brace
    while (count2 < textLine.length())
    {
        nextCharacter =textLine.at(count2);
        if (EOF)
        {
           textLine.replace (count2, 1, " {");
          }
        else
      {
         textLine.replace (count2, 1, "{/n");
      }
    count2++;
   system("pause");
return 0;
}



QuestionDetails:

  1. Convert all tab characters to double spaces.
  2. Whenever a left brace ("{") is encountered: (This is the part, if someone can give me a sample insertion,I would appreciate it. I don't need the answer to the homeworkassignment, just an example of how to get this next part, then Ithink it would come together.)



    1. Add 2 to the indentation count (initially zero)
    2. If the brace is not the last character on the line, inserta
      newline immediately after the brace.

  3. Whenever a right brace ("}") is encountered:

    1. Subtract 2 from the indentation count.
    2. If the brace is not the first character on the line, inserta
      newline immediately before the brace.

  4. Change the number of blank spaces at the front of each line tobe
    consistent with the indentation count. The easiest way to do thisis to
    delete all blank spaces (using a loop) and then insert thecorrect
    number of spaces (indentation count). There are string functionsthat
    will simplify the coding for these actions. (maybe an example of this too.)




    Correct indentation for program comments, for braces embeddedwithin
    comments or strings, and for continuation lines is not required,though
    you may
    attempt to incorporate these into your program as well if you'dlike a
    bit more of a challenge.




Hints:

The input can be processed either line-by-line orbyte-by-byte.
In either
case, use a single loop to process the input stream.

The following statement returns the next character fromthe
input file, without removing it from the input buffer:

char next =
cin.peek();

This is what I have so far, can you help, the deeper I get the morelost I get. What am I doing wrong?

#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main() {
string inFileName, outFileName, inLine, textLine;
char nextCharacter;
ifstream inFile;
ofstream outFile;
int count = 0;
   
cout << "Enter the input file name: ";
cin >> inFileName;

inFile.open(inFileName.c_str());
if (inFile.fail()) {
    cout << "The input file (" <<inFileName << ") can not be opened." << endl;
    system("pause.exe"); // wait for user to pressRETURN
   return 0;
     }

while(!inFile.eof()) {
    char inChar = inFile.get();
    if (!inFile.eof() && inChar == 10) {
      count++;
    }
}
   while (count < textLine.length () &&(!EOF))
        nextCharacter =textLine('{',0);
        if (nextCharacter >=0)
        {
           indentCount = indentCount + 2;
           cout << "Indention Count" << indentCount <<endl;
           count++;
         }
        else
    // if brace is not last character, insertnewline after brace
    while (count2 < textLine.length())
    {
        nextCharacter =textLine.at(count2);
        if (EOF)
        {
           textLine.replace (count2, 1, " {");
          }
        else
      {
         textLine.replace (count2, 1, "{/n");
      }
    count2++;
   system("pause");
return 0;
}

Explanation / Answer

please rate - thanks sorry best I can do, even when I use the debugger, it's not working theway the code says to #include #include #include #include using namespace std; int main() { string inFileName, outFileName, inLine, textLine; char nextCharacter; bool nonblankfound=false,noread=false,notoutput=true; ifstream inFile; ofstream outFile; int indentCount = 0,i,j; int start=0; cout > inFileName; inFile.open(inFileName.c_str()); if (inFile.fail()) {     cout
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