Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that reads from a file name specified in the command line as an argument, and ignores any extra command line arguments

image text in transcribed

Write a C++ program that reads from a file name specified in the command line as an argument, and ignores any extra command line arguments that are provided after the file name. However, if no file name is provided, the program should use the standard input instead of a file. If the file cannot be opened, print on a new line "File cannot be opened: ", followed the file name, and exit. The program should read from the file character by character until the end of file. If the input file is empty, print out the message "File is empty." on a new line and then exit. The program should count the number of lines, number of words, number of characters, number of digit characters (O - 9'), and the number of alphabetic characters seen in the file. For example, with an input file of the following contents: 3456 Georgre 1234 smith 4321 staci 278 sandra 10.25 4.5 12.75 25.35 The displayed output is as shown below: LINES: 4 WORDS: 12 CHARS: 75 DIGITS: 29 LETTERS: 21 Hints: 1. Use functions such as: isdigit(), isalpha(), and isspace(). 2. You can use get() method for reading from the input. 3. Download the zipped file for the test cases from Canvas. These are the test cases you will be graded against on your submission to Vocareum. Use the test cases to test your implementation. Note that case 1 myfilel is not included in the set. Your program will be checked against a file name, myfile1, that does not exist. 4. There are 4 test cases. Case 2 is for an empty file, myfile2. Note that case 3 is for checking you against no file is provided in the command line and your program switches to read from the stdin. The input for case 3 is from myfile3 on vocareum. Case 4 reads from a provided file name in the command line, myfile4

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

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

Show that - and ( ) + ( ) + ( ) are orthogonal.

Answered: 1 week ago

Question

2. What are the potential strengths of group discussion?

Answered: 1 week ago