Accept a string parameter representing a file name

Assignment Help Computer Engineering
Reference no: EM132218403

Write a function named input_stats that accepts a string parameter representing a file name, then opens/reads that file's contents and prints information to the console about the file's lines.

Report the length of each line, the number of lines in the file, the length of the longest line, and the average characters per line, in exactly the format shown below.

You may assume that the input file contains at least one line of input. For example, if the input file carroll.txtcontains the following data:

Beware the Jabberwock, my son, the jaws that bite, the claws that catch, Beware the JubJub bird and shun the frumious bandersnatch.
Then the call of input_stats("carroll.txt") should produce the following console output:

Line 1 has 30 chars Line 2 has 41 chars Line 3 has 0 chars Line 4 has 31 chars Line 5 has 26 chars 5 lines longest = 41, average = 25.6
If the input file does not exist or is not readable, your function should prno output. If the file does exist, you may assume that the file contains at least 1 line of input.

Constraints: Your solution should read the file only once, not make multiple passes over the file data.

Reference no: EM132218403

Questions Cloud

Which theorist fathered the principle : Based on your readings and research, develop a timeline of five key management theory/principle milestones over time. Please address the following questions.
Write some code that counts the number of times the value : Write some code that counts the number of times the value associated with student_id appears in the list associated with incompletes.
Identify the different target markets : Identify the different target markets and, using segmentation characteristics and any other applicable concepts, evaluate and explain your reasons.
Write matlab code that will start with a positive integer : Write MATLAB code that will start with a positive integer and run through this process until a 1 is reached.
Accept a string parameter representing a file name : Write a function named input_stats that accepts a string parameter representing a file name, then opens/reads that file's contents and prints information.
To which namespace does the file class belong : Which of the following methods could be used to retrieve a decimal value from a binary file? To which namespace does the File class belong?
Which method will be executed as a result : If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.
What is the global cpi for each implementation : What is the global CPI for each implementation? Find the clock cycles required in both cases.
Post a working approach for the topic you chose : Read: "Topics and Approaches to the Literary Essay" in the Resources folder. Choose one of the topics provided for you, or email the professor for approval.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Define what is the difference between an insider attack

How would we determine what assets we have, what needs to be protected, and how to protect them

  How do you now combine the field to get back original output

How do you display the date output with each field on a separate line? How do you now combine the fields to get back the original output?

  Questionconsider an adt called square matrix the matrix can

questionconsider an adt called square matrix. the matrix can be represented by a 2-dimensional array of integers with n

  Evaluate or change variables in your program

The Debugger lets you break, or halt, the execution of your program to examine your code, and evaluate or change variables in your program.

  Calculate the average temperature for the year

Write a program to calculate the average temperature for the year and determine the hottest month of the year.

  Evaluate a 2d game for pc

There are thousand of games on the web. Use Google to search for games for all platforms and come up with an idea and a title that fully reflects the main theme of your game

  Find out coding of binary information and error detection

find out Coding of Binary Information and Error Detection.

  What types of businesses it is best suited

describe its capabilities, for what types of businesses it is best suited, and its cost to purchase and install

  Write a class relationship between these classes

Write a class relationship between these classes that reflects this relationship. Details of other members are not important.

  Determine obstacles for an organization

There are four (4) critical success factors that are important for effective risk management: supportive organization; competent people; appropriate methods.

  Assess the product by using the five-step plan that is

imagining yourself to be the customer construct a house of quality to provide the organization with your perspectives

  Write a lc-3 assembly program to subtract two integers

Write a LC-3 assembly program to subtract two integers (between 0 and 9) provided by the user.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd