Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help needed with C++ code i will up vote! only done in C++ Write a C++ program that acts like a simple counting tool for

Help needed with C++ code i will up vote! only done in C++
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Write a C++ program that acts like a simple counting tool for collecting information from textual files of documents prepared for a simple scripting language interpreter. An input file for the simple scripting interpreter includes two types of data, commented lines and scripting code lines. A commented line is recognized by either the two characters " A" or " " at the beginning of the line, which would be skipped by the scripting interpreter. All other noncommented lines are considered as part of the scripting code, including any blank lines with whitespace. The program for the simple counting tool should read lines from a file until the end of file. The program should prompt the user for the file name to read from. The program should open the file for reading, and if the file cannot be opened, it should print the message "File cannot be opened" " followed by the filename, and exit. After reading the contents of the input file, the program should print out the total number of lines, the number of commented lines, the maximum length of commented lines, the maximum length of non-commented lines, the commented line of maximum length delifnited by double quotes, and the noncommented line of maximum length delimited by double quotes. See the examples in the presentation shides for the expected output format. \begin{tabular}{l|l} Line number & File contents \\ \hline 1 & run prog1 \\ 2 & /l \\ 3 & delete \\ 4 & \#\# execute next command \\ 5 & delete myfile \\ 6 & \\ 7 & \\ 8 & copy filel file2 \\ 9 & // welcome to cs 280 \\ 10 \\ 11 \\ 12 & print myfile \\ 13 \\ End of File marker & // terminate script \end{tabular} Hinclude iostream \#include iomanip> using namespace std; int main() \{ ifstream inclientFiley string filename; I/ if a filename is provided, open file cout "Enter the name of a file to read from: " endl; cin filenamej inclientFile. open (filename. cstr()); if ( linclientFile) \{ cerr \& endl; cerr "File cannot be opened" exit (1); \} cout left setw (18) "Account" set(13) "Name" "Balance" endl fixed showpoint int account; char name[ 30 ]. double balances II display each record in file while (inclientfile account name balance) f. cout left setw (10) account setw(13) name setw(8) setprecision (2) right balance end 13 J I/ end while return e3 If ifstream destructor closes file 3I end main using namespace std; j int main() int character; // II prompt user to enter line of text cout "Before input, cin.eof() is "ks cin.eof() endl \& "Enter a sentence followed by end-of-file:"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. How do todays organizations diff er from those of earlier eras?

Answered: 1 week ago

Question

Developing and delivering learning that is integrated with the job.

Answered: 1 week ago

Question

Use of assessments to determine trainees learning styles.

Answered: 1 week ago

Question

7. Discuss the advantages of embedded learning.

Answered: 1 week ago