Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer by C++ Line and letter count Write a program that reads a given text, outputs the text as is, and prints the number

Please answer by C++

image text in transcribed

image text in transcribed

image text in transcribed

Line and letter count Write a program that reads a given text, outputs the text as is, and prints the number of lines and the number of times each letter appears in the text. An uppercase letter and a lowercase letter are treated as being the same; that is, they are tallied together. Because there are 26 letters, we use an array of 26 components to perform the letter count. We also need a variable to store the line count. The text is stored in a file, which we will call textin.txt. The output will be stored in a file, which we will call textout.out. Input A file containing the text to be processed. Output A file containing the text, number of lines, and the number of times a letter appears in the text. Based on the desired output, we must output the text as is. That is, if the text contains any whitespace characters, they must be output as well. Furthermore, we must count the number of lines in the text. Therefore, we must know where the line ends, which means that we must trap the newline character. This requirement suggests that we cannot use the extraction operator to process the input file. Because we also need to perform the letter count, we use the get() function to read the text. Variable These statements indicate that the function main needs (at least) the following variables: The variable lineCount and the array letterCount need to initialize to 0 in initialize function. To get the character one by one, we can use get(), for example infile.get (ch) . For the array letterCount [26], it use to store the occurrence of each letter, e.g. , letterCount[0] stores the A count, letterCount[1] stores the B count, and so on. Since letters "A", "B", " C ", etc. are character data type, meanwhile the index of an array is integer, so we may to use static_cast > to do the conversation. According to ASCll code, the letters are converted to following integers. After the conversation, we need to minus each character by the ASCII value of character "A" (i.e. 65), then it becomes an index value in letterCount. The algorithm for the program is: 1. Declare the variables. 2. Open the input and output files. 3. Initialize the variables. 4. While there is more data in the input file: a. For each character in a line: i. Read and write the character. ii. Increment the appropriate letter count. b. Increment the line count. 5. Output the line count and letter counts. 6. Close the files. To simplify the function main, we divide it into four functions: - Function initialize - Function copyText - Function characterCount - Function writeTotal Sample Run (textout.out): Today we 1 ive in an era where information is processed almost at the speedoflight. Through computers, the technological revolution is drastically changing the way we live and commanicate with one another. Terms such as "the Internet, " which were unfamiliar just a few years ago, are very common today. Withthe help of computersyou can send letters to, and receive letters from, loved ones within secondls. You no longer need to send a rsum by mail to apply for a job; in many cases you can simply sulmit your job application via the Internet. You can watch how stocks perform in real time, and instant ly buy and sell them. Students regularly "surf" the Internet and use computers to design their classrocm projects. They a lso use powerful word-processing software to complete their term papers. Many peoplemaintain andbalance their checkbooks on ccmputers. The number of 11 nes =15 A count =53 B count =7 C count =30 D count =19 E count =81 F count =11 G count =10 H count =29 I count =41 J count =4 K count =3 L. count =31 M eount =26 N count =50 0 count =59 P count =21 Q count =0 R count =45 s count =48 T count =62 v count =24 v count =7 % count =15 x count =0 Y count =20 z count =0

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

Students also viewed these Databases questions

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago