Question: Problem A) (20 Points) Computing the Probability of Character Occurrence Many string analysis tasks (particularly in genomics and cryptography) involve counting character occurrences. Give a

Problem A) (20 Points) Computing the Probability of Character Occurrence Many string analysis tasks (particularly in genomics and cryptography) involve counting character occurrences. Give a string, we would like to find the probability of occurrence of each character, relative to the other alphabetic characters in the string. For example, each character in the string "supercalifragilisticexpialidocious" has the following probability of occurrence: a: 8.8%, c: 8.8%, d: 2.9%, e: 5.9%, f: 2.9%, g: 2.9%, i: 20.6%, 1: 8.8%, o: 5.9%, p: 5.9%, r: 5.9%, s: 8.8%, t: 2.9%, u:5.9%, x: 2.9% Write a C++ program that accepts a string as input from a user and calculates the probability of occurrence (a percentage) for each alphabetic character in the word. Use an array to store the counts of each character. Below are examples from three different runs of the program. Enter a string: supercalifragilisticexpialidocious 8.8% 8.8% a: c: 5.9% 2.9% e: i: 1: 26.6% 8.8% 5.9% 5.9% 5.9% 8.8% 2.9% 5.9% r: s: t: u: Enter a string: The quick brown fox jumps over the lazy dog Enter a string: The quick brown fox jumps over the lazy dog 2.9% 2.9% 2.9% 2.9% 8.6% a: c: 2.9% 57% 2.9% 2.9% 2.9% j: 2.9% 2.9% 11.4% 2.9% 2.9% 5.7% 2.9% 5.7% 57% 2.9% 2.9% o : r: S: u: 2.9% 2.9% Enter a string: First line (press Enter) Second line (press Enter) (press Enter, this is an empty line) c: 5.3% e: f: i: 1: n: O: r: s: t: 5.3% 15.8% 5.3% 15.8% 18.5% 15.8% 5.3% 10.5% 5.3% Enter a string: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla imp erdiet sollicitudin dolor nec aliquet. Cras facilisis luctus tristique Aliquam volutpat nulla a pretium feugiat. Curabitur semper mi ut odio ornare viverra. Nu lla mi felis, mollis et dui eu, faucibus mollis risus. Maecenas bibendum consequ at risus, id suscipit quam dapibus porta. vivamus a velit lectus. Aenean eget te llus convallis, faucibus ex ut, auctor justo. Maecenas vel elementum massa. Susp endisse efficitur lectus pretium sem congue commodo. Proin magna purus, viverra in egestas nec, tempus sed massa. Proin euismod blandit dolor ac viverra. Sed mo lestie sit amet orci auctor suscipit 8.3% 1.3% 5.0% 3.1% c: f: 1: 1: 1.3% 18.5% 6.2% 5.3% 5.5% 2.9% 0.9% o: 9.5% 7.3% 8.8% 2.2% 0.2% t: u: Constraints: 1. Input could be multiple lines, it ends with an empty line, as illustrated in the third example Note the additional empty line after the last line of text entered in each of the examples of text) signals the end of the input. (hint: loop until str, from getline(cin, str) is empty) 2. We only count alphabetic characters(i.e. a~z and A~-Z), so that the sum of the percentages above. Entering an empty line (i.e. hitting the enter key twice after entering the last line 3. Use an array to store the counts of each character. 4. Note, your program should function correctly on any data set that conforms to the specifications documented above, so you should be sure to test your on more than one data set. Write, test, and correct your program. Have all the functions, including main, in a single file with the function definitions after main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
