Deadline-2 hrs asap
pay-250
Reading Files using Loops and Functions
Task 1
Task 2Open the filename using an ifstream and check to make sure it worked.
Create a new file to save the results in using an ofstream. The file should be named based on the letter given. For example, if I callstart_with_letter("example
Read each word in the file. If it starts with the upper or lower case version of the letter given as input, write the word to your output file followed by a newline and increase your count.
Close both files and return the count.
string res_name="results_";
res_name+=letter;
res_name+=".txt";
Task 3
Task 4
Overview: We will take a book and count how many words start with each letter. We will also make a set of result files that store all words starting with each letter.
Review the ASCII character codes for this lab ASCII Table
Read about how files work in C++ https://www.tutorialspoint
Create a new file lab6.cpp.
Write a function int starts_with_letter(string filename, char letter) that takes a file and writes all the words that start with the given letter into a file. The function returns the number of words it put into the file.
Here is an outline for how your function should work.
Hints: Use ASCII codes to account for both upper and lower case letters. The below code shows you how to generate a file name to use.
Write your main program. Ask the user for the name of a file. Open the file and count how many words starting with each letter A-Z appear. The output is the total number of words that start with each letter. The program should also make a file for each letter with the actual words found, one word per line. When the program exists, you should have 26 new files with results. (See Attached Example File)
Go to Project Gutenberg and download a plain text copy of "Fundamental Principles of the Metaphysic of Morals" by Immanuel Kant. Run your program on it. Books from Project Gutenberg have copyright and additional material at the beginning and end, just leave this in the file as it is for this lab
Get Free Quote!
300 Experts Online