Programming Exercises

  1. File Content Reverse Display

Write a program that reads a file containing a series of strings and displays the content of the file in reverse order, starting from the last line to the first.

 

  1. File Tail Display

Write a program that asks the user for the name of a file and displays the last five lines of the file’s contents. If the file contains less than five lines, it should display the file’s entire contents.

 

  1. Word Counter

Write a program that asks the user for the name of a file. The program should read the file and display the total number of words in the file.

 

  1. Vowel Counter

Assume a file containing a series of strings is named and exists on the computer’s disk. Write a program that counts the number of vowels (a, e, i, o, u) in the file and displays the count.

 

  1. Character Frequency

Write a program that asks the user for the name of a file. The program should read the file and display the frequency of each character in the file.

 

  1. Word Frequency

Write a program that asks the user for the name of a file. The program should read the file and display the frequency of each word in the file.

 

  1. Longest Line

Write a program that asks the user for the name of a file. The program should read the file and display the longest line in the file.

 

  1. Unique Words

Write a program that asks the user for the name of a file. The program should read the file and display all unique words in the file.

 

  1. Duplicate Line Removal

Write a program that asks the user for the name of a file. The program should read the file and create a new file that contains the same content but with all duplicate lines removed.

 

  1. File Content Search

Write a program that asks the user for the name of a file and a search term. The program should read the file and display all lines that contain the search term.