Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solution must be in C++. No global variables and No continue statement. The more simple the solution the better. Goals Gain experience with file I/O

Solution must be in C++. No global variables and No continue statement. The more simple the solution the better.

Goals

Gain experience with file I/O in C++

For this question, we will implement a program that reads a file filled with letters, count the letter frequencies in the file, and write the results to a new file.

Requirements

Input File

For simplicity, you can download this example file as the input file: file_of_text.txt or, you can also create your own input files.

File should consist of only a - z, A Z, space character, newline characters.

Program

Your program should first ask for the file the user would like to read, then read the file chosen by the user. The program will continue counting letters until the EOF (end of file) character. For each paragraph in the input file, the program should count the frequency of each letters, ask user what filename to output to, then proceed to output the frequencies to the file. Each paragraph should have its own output file.

Note: The letter counting disregards the upper/lower case differences. This means, capitalized letter F is treated like f, and counted toward frequency of f.

Note: the paragraphs are separated by newline characters.

So, the following input file means 3 paragraphs: (not counting the quotation mark)

Hello I am a CS major

I am having fun

This is a placeholder

The format of the output file is as follows:

a: 3

b: 0

c: 1

d: 0

z: 0

Functions

The following is the functions of the program. You can make more function if you would like.

void count_letters(ifstream &, int*);

void output_letters(ofstream&, int*);

The requirements of each functions are specified below.

void count_letters(ifstream &, int*)

count_letter function takes an input file stream variable, and a pointer to an array of integers.

The function first reads the paragraph string from the input file stream, then counts the letter frequencies of that paragraph, and store the frequencies in the array. Disregards upper/lower case letters.

void output_letters(ofstream &, int*)

output_letters function takes an output file stream variable, and a pointer to an array of integers that contains frequencies of letters.

The function first asks user for the filename the user would like to output to, then outputs the frequencies of letters to the output file in the format specified above.

File I/O

If the program fails to open input file, then the program can either terminate, or recovers from error and re-prompt user for a new file name.

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

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions

Question

What is the job being performed?

Answered: 1 week ago