Menu

[Solved]Question 2 Required Open Input File Shown Read One Character Time Characters File Read Rea Q37123167

In C++
Question 2 You are required to open an input file (shown below) then read one character at a time until all characters in theHere will be the output generated Letters and its count: A occurs1 time B occurs: 1 time C occurs1 time D occurs 1 time E occLetters and its count: A occurs1 time B occurs 1 time C occurs1 time D occurs1 time E occurs 3 times F occurs 1 time G occursThe other counts of 4 accounts for the dot at end of line #1 and the second line % and # in It should be noted that since blaQuestion 2 You are required to open an input file (shown below) then read one character at a time until all characters in the file are all read. While reading the content of the file, keep a count of the following: 1) Count of each digit read. The counts should be kept in an int array of size 10 2) Count of each alphabetic character read irrespective if it is an upper case or lower case. The counts should be kept in an int array of size 26 3) Count of whitespace characters. A whitespace includes the blank (space) ‘,new line character In, tab character It, form feed f, Vertical tab v and carriage return r. 4) Count of all other characters not alphabetic, not a digit and not a whitespace 5) Total count of all characters read After reading and processing the file, and get each count correctly, you will display each letter of alphabet and its count, each digit and its count, count of whitespaces and all other counts. Your solution must use FUNCTIONAL DECOMPOSITION Hence, if the input file was the one given below, your unsorted output is shown below. Please note that your output must also has the values sorted in numerical order from lowest to highest. Here is the content of your input file. main.cpp source.tx The quick brown fox jumps over the lazy dog Here will be the output generated Letters and its count: A occurs1 time B occurs: 1 time C occurs1 time D occurs 1 time E occurs3 times. F occurs1 time G occurs 1 time H occurs2 times. I occurs:1 time. J occurs: 1 time K occurs 1 time L occurs:1 time M occurs1 time N occurs 1 time. 0 occurs:4 times P occurs 1 time Q occurs1 time R occurs:2 times S occurs1 time T occurs 2 times. U occurs:2 times V occurs 1 time W occurs1 time X occurs1 time. Y occurs 1 time Z occurs 1 time Now, if you add digits and other characters to the input file as shown below main.cpp source.tx The quick brown fox jumps over the lazy dog 01234567890011 22 This will be the content of your test file and you MUST use it to test your program for submission Letters and its count: A occurs1 time B occurs 1 time C occurs1 time D occurs1 time E occurs 3 times F occurs 1 time G occurs1 time H occurs 2 times I occurs1 time occurs:1 time K occurs 1 time L occurs 1 time M occurs1 time N occurs1 time 0 occurs4 times P occurs 1 time Q occurs 1 time R occurs 2 times S occurs 1 time T occurs 2 times U occurs2 times V occurs1 time W occurs: 1 time X occurs 1 time Y occurs1 time Z occurs 1 time Digits and its count: 0 occurs: 3 times 1 occurs:3 times 2 occurs 3 times 3 occurs1 time 4 occurs 1 time 5 occurs1 time. 6 occurs 1 time. 7 occurs:1 time 8 occurs 1 time 9 occurs:1 time Whitespace counts: 13 Other counts: 4 Note that the counts of 13 refers to count of all whitespace characters. From the input file above, there are 11 blank characters and 2 new line characters which totals to 13 The other counts of 4 accounts for the dot at end of line #1 and the second line % and # in It should be noted that since blanks are read in from the file, it means that you cannot use the extraction operator >> to read a character from file since the> operator does ignore the blank characters but in this exercise, you are required to count blank character. HINTS: You should have an array for the count of each letter and also an array for the count of each digit For example: 6 using namespace std; 7 const int NUM LETTERS 26; 8 const int NUM DIGITS-10; 1 int main() 12 13 14 15 nt countLetters [NUM LETTERS] () //count for each letter 16 int digitCounts [NUM DIGITS]-(//count of digits ifstream infile; for input file char ch int blankCounts-0 int otherCounts-0 //count of anything not a letter and not a digit and not blank 18 19 Hence, in the array countLetters, the first position (index ) will be the count for letter ‘a or ‘A’ (case does not matter) The second position will be the count for letter ‘b’ or B, and so on So, if a read an ‘a or ‘A’, you increment the first position of the array and so on for each letter of the alphabet This determination of which element in the array to be incremented can be a very long nested if-else as you need to check each of the 26 letters of alphabet. It will be the same thing for the 10 digits However, it can be replaced with a much simpler one line statement but first get it to work! You MUST use the same input data file above when testing your program Show transcribed image text Question 2 You are required to open an input file (shown below) then read one character at a time until all characters in the file are all read. While reading the content of the file, keep a count of the following: 1) Count of each digit read. The counts should be kept in an int array of size 10 2) Count of each alphabetic character read irrespective if it is an upper case or lower case. The counts should be kept in an int array of size 26 3) Count of whitespace characters. A whitespace includes the blank (space) ‘,new line character In, tab character It, form feed f, Vertical tab v and carriage return r. 4) Count of all other characters not alphabetic, not a digit and not a whitespace 5) Total count of all characters read After reading and processing the file, and get each count correctly, you will display each letter of alphabet and its count, each digit and its count, count of whitespaces and all other counts. Your solution must use FUNCTIONAL DECOMPOSITION Hence, if the input file was the one given below, your unsorted output is shown below. Please note that your output must also has the values sorted in numerical order from lowest to highest. Here is the content of your input file. main.cpp source.tx The quick brown fox jumps over the lazy dog
Here will be the output generated Letters and its count: A occurs1 time B occurs: 1 time C occurs1 time D occurs 1 time E occurs3 times. F occurs1 time G occurs 1 time H occurs2 times. I occurs:1 time. J occurs: 1 time K occurs 1 time L occurs:1 time M occurs1 time N occurs 1 time. 0 occurs:4 times P occurs 1 time Q occurs1 time R occurs:2 times S occurs1 time T occurs 2 times. U occurs:2 times V occurs 1 time W occurs1 time X occurs1 time. Y occurs 1 time Z occurs 1 time Now, if you add digits and other characters to the input file as shown below main.cpp source.tx The quick brown fox jumps over the lazy dog 01234567890011 22 This will be the content of your test file and you MUST use it to test your program for submission
Letters and its count: A occurs1 time B occurs 1 time C occurs1 time D occurs1 time E occurs 3 times F occurs 1 time G occurs1 time H occurs 2 times I occurs1 time occurs:1 time K occurs 1 time L occurs 1 time M occurs1 time N occurs1 time 0 occurs4 times P occurs 1 time Q occurs 1 time R occurs 2 times S occurs 1 time T occurs 2 times U occurs2 times V occurs1 time W occurs: 1 time X occurs 1 time Y occurs1 time Z occurs 1 time Digits and its count: 0 occurs: 3 times 1 occurs:3 times 2 occurs 3 times 3 occurs1 time 4 occurs 1 time 5 occurs1 time. 6 occurs 1 time. 7 occurs:1 time 8 occurs 1 time 9 occurs:1 time Whitespace counts: 13 Other counts: 4 Note that the counts of 13 refers to count of all whitespace characters. From the input file above, there are 11 blank characters and 2 new line characters which totals to 13
The other counts of 4 accounts for the dot at end of line #1 and the second line % and # in It should be noted that since blanks are read in from the file, it means that you cannot use the extraction operator >> to read a character from file since the> operator does ignore the blank characters but in this exercise, you are required to count blank character. HINTS: You should have an array for the count of each letter and also an array for the count of each digit For example: 6 using namespace std; 7 const int NUM LETTERS 26; 8 const int NUM DIGITS-10; 1 int main() 12 13 14 15 nt countLetters [NUM LETTERS] () //count for each letter 16 int digitCounts [NUM DIGITS]-(//count of digits ifstream infile; for input file char ch int blankCounts-0 int otherCounts-0 //count of anything not a letter and not a digit and not blank 18 19 Hence, in the array countLetters, the first position (index ) will be the count for letter ‘a or ‘A’ (case does not matter) The second position will be the count for letter ‘b’ or B, and so on So, if a read an ‘a or ‘A’, you increment the first position of the array and so on for each letter of the alphabet This determination of which element in the array to be incremented can be a very long nested if-else as you need to check each of the 26 letters of alphabet. It will be the same thing for the 10 digits However, it can be replaced with a much simpler one line statement but first get it to work! You MUST use the same input data file above when testing your program

Expert Answer


Answer to Question 2 You are required to open an input file (shown below) then read one character at a time until all characters i… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *