Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code: #include #include #include #include #include using namespace std; int main() { ifstream file; string filename, str, word; int Lcount=0, Wcount=0, Icount=0, BLcount=0, i=0;

My code:

#include #include #include #include #include

using namespace std;

int main() { ifstream file; string filename, str, word; int Lcount=0, Wcount=0, Icount=0, BLcount=0, i=0; bool isInt = false;

cout > filename;

file.open(filename.c_str());

if(!file) { cerr

getline(file, str); while(!file.eof()) { Lcount++; if(str.length()==0 || str==" ") { BLcount ++; getline(file, str); continue; } str += " "; istringstream ss(str); ss >> word; while(ss.good()){ Wcount++; i=0; if(i==0 && (isdigit(word.at(0) || word[0]== '-' || word[0] == '+'))){ isInt = true; i++; } while(i>word; } getline(file, str); } cout

return 0; }

The code is working but I have to upload it through self-check software and it is not giving me any credit because the output has to be exact. Can someone help with that,image text in transcribedimage text in transcribedimage text in transcribed please?image text in transcribed

RESULT: case3 [ 0 / 1] RUNNING case4 Enter Filename: Enter the name of a file to read from: Total Number of Lines: 6 Number of non-blank lines: 4 Number of Words: 5 Number of Integers: 3 1c1,2 Enter the name of a file to read from: > Total Number of Lines: 6 4c5 Number of Integers: 5 RESULT: case4 [ 0 1] RUNNING case5 Enter Filename: Enter the name of a file to read from: Total Number of Lines: 9 Number of non-blank lines: 6 Number of Words: 10 Number of Integers: 0 1c1,2 Enter the name of a file to read from: > Total Number of Lines: 9 RESULT: case5 ( 0 / 1] RUNNING case6 Enter Filename: Enter the name of a file to read from: Total Number of Lines: 11 Number of non-blank lines: 5 Number of Words: 16 Number of Integers: 5 1cl, 2 Enter the name of a file to read from: > Total Number of Lines: 11 4c5 Number of Integers: 7 RESULT: case6 [ 0 / 1 ] SUMMARY: RESULT: compiles [1/1] RESULT: casel [ 0 / 1] RESULT: case2 [ 0 / 1] RESULT: case3 [ 0 / 1 ] RESULT: case4 [ 0 / 1] RESULT: case5 [ 0 / 1 ] [ Executing 'RUN'...] Write a C++ program that reads 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, print the message "File could not be opened", followed by a space and the filename, and exit. The program should keep track of the number of lines, the number of non-blank lines, the number of words, and the number of integers read from the file. An integer is defined as a one or more digits, with an optional sign preceding the number, with no spaces separating the sign and the number. For example, 17234, -354, and +639 are integers, but 17.234, -+23 are not. A word is defined as a sequence of one or more non-whitespace characters separated by whitespace. At the end of file, the program should print out the total number of lines, the number of non-blank lines, the number of words, and the number of integers. Note that a line having only whitespace characters is a non-blank line as well. For example, given the following file, staci james + George - +123 12.56 smith beth -4.75 Note: There are 9 lines in this input file. the generated output results after reading the file contents are as follows: Total Number of Lines: 9 Number of non-blank lines: 5 Number of Words: 10 Number of Integers: 0 Note: The screen pointer is at a new line after displaying the results. You have to apply the same format in order to have exact match. ccc_v1_w_e5429_17437@runweb1:-$ [ Executing 'RUN'... ] ccc_v1_w_e5429_17437@runweb1:~$ ccc_v1_w_e5429_17437@runwebl:-$ cd; VOC_SELECTED_FILE="RA2_Faizan_Alam.cpp" /bin/ SUCCESS! RESULT: compiles [1 / 1] RUNNING casel Enter Filename: File could not be opened infilel 1c1, 2 Enter the name of a file to read from: > File could not be opened infilel No newline at end of file RESULT: casel [ 0 1 1 ] RUNNING case2 Enter Filename: Enter the name of a file to read from: Total Number of Lines: 0 Number of non-blank lines: 0 Number of Words: 0 Number of Integers: 0 1c1,2 Enter the name of a file to read from: > Total Number of Lines: 0 RESULT: case2 [ 0 / 1] RUNNING case 3 Enter Filename: Enter the name of a file to read from: Total Number of Lines: 5 Number of non-blank lines: 3 Number of Words: 0 Number of Integers: 0 1c1,2 Enter the name of a file to read from: > Total Number of Lines: 5

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

Define Administration and Management

Answered: 1 week ago