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

You need to review file input, and whie loops for this program. A) Write a progr

ID: 3773722 • Letter: Y

Question

You need to review file input, and whie loops for this program.

A) Write a program that reads text from a file and outputs the following statistics about the file

1) Word count HINT: Read the file using >>

2) Character count HINT: Read the file using get function

Check your program for the attached input file called speech.txt.Verify the answer from your program by using word document to count the number of characters and words.

B) This program requires a bit of thinking:

Write a program that takes a C++ file as input and checks if the file has certain syntax errors. Since a real syntax checke can be very complicated, we only want to implement a partial one. We will also assume that the input file is formatted nicely and has no comments. The syntax checker should do the following

1) report missing semicolons. You only need to report the first missing semicolon HINT use getline function but be careful because certain statements dont end with semicolons

2) report unbalanced curly braces. When the file is completely parsed, report if the total number of open braces is equal to closed ones.

Check your program for the attached input file called lab.cpp. Verify the answer from your program by using a compiler.

Explanation / Answer

Part A

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

using namespace std;

int main()
{
ifstream input_file;
input_file.open( "speech.txt", ios::in );
   string w;
    int w_count = 0;
    int char_count=0;
    char character;

    while( !input_file.eof() )
    {
      input_file >> w;
      if( w.length() > 0 )
      {
        w_count++;
      }
      character = input_file.get();
  if(character != ' ')
   ++char_count;
}

cout << "Character count is" << char_count << endl;

    cout << "Word count is" << w_count << 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