Sheet 07: File Processing Solution



Programming Exercises:

1- Word Count: A common utility on UniX/Linux systems is a small program called ”we.” This program analyzes a file to determine the number of lines, words, and characters contained therein. Write your own version of “wc”. The program should accept a file name as input and then print three numbers showing the count of lines, words, and characters in the file.

2- Write a program that calculates the average word length in a text file.

3- Write a program to draw a quiz score histogram. Your program should read data from a file. Each line of the file contains a number in the range 0- 10. Your program must count the number of occurrences of each score and then print a horizontal bar chart (stars) with a bar for each possible score (0-10) with a width corresponding to the count of that score. For example, if 15 students got an 8, then the width of the bar for 8 should be 15 stars. A simple example is as follows:-

  1. *

  1. ****

  2. ********

  1. **********

  2. **************

  1. *********************

  2. ***************************

  1. ************************************

  2. ******************************

  1. *****************

  2. ******************


error: Content is protected !!