Question: O Evaluation Separation of concerns Does each class perform a distinct part of the entire solution? Does each class contain logically related set of responsibilities?




O Evaluation Separation of concerns Does each class perform a distinct part of the entire solution? Does each class contain logically related set of responsibilities? Does each method defined in a class perform have one distinct responsibility within the class? Design for reuse Is each method defined to allow reuse within the class? O O Description Develop a Python solution to the following problem. a. 1. Your solution must rewrite the Assign01original.py solution to: Define one or more classes to perform all of the letter frequency counting. b. Modify the two test functions so they use the classes defined in step 1a. Run your OOP solution to ensure it produces the same results as the Assign010riginal.py solution. C. assign010riginal.py #The following is used as a global constant (i.e., it's value is never changed) ORD_LOWER_A = ord('a') #purposes Open a file in read-mode. #inputs: filename - a string object containing a file name. #outputs: returns a file object. #assumptions: none. def openFile(fileName): inFile = None try: in File = open(fileName, T') except Exception as ex: print("An exception occured: ", ex) return infile #purpose: Increment letter counts for entire input file. #inputs: inFile - file containing text. list Freq - list containing frequences for 'a', 'b' dictFreq - dictonary containing frequences for 'a', 'b' #assumptions: in file has been opened. def countLetters(infile, listFreq, dictFreq): textLine = inFile.readline().lower() while len(textLine) > 0: countLetters_one TextLine(textLine, listFreq, dictFreq) textLine = inFile.readline().lower) #purpose: Increment letter counts for a single text line. #inputs: textLine a string object containing one text line from the input file. list Freq - list containing frequences for 'a', 'b',...,' dictFreg - dictonary containing frequences for 'a','b',...,'Z'. #outputs: updates listFreq and dictFreq. #assumptions: list Freq initialized to 26 zeros. dictFreq is initially an empty dictionary. def countletters_one TextLine(textLine, listFreq, dictFreq): for char in textLine: if char.isalpha (: #update frequency in list. charIdx = ord(char) - ORD_LOWER_A list Freq[charIdx] = list Freq[charIdx] + 1 #update frequency in dictionary. if char in dictFreq: dict Freq[char] = dictFreq[char] + 1 else: dictFreq[char] = 1 #purpose: Display letter frequences contained in listFreg and dictFreq. #inputs: listFreq and dictFreq. #outputs: Displays frequency data to console. #assumptions: none. def display(listFreq, dictFreq): for idx in range(len(listFreq)): char = chr(ORD_LOWER_A + idx) dFreq = 0 if char in dictFreq: dFreq = dictFreq[char] print(char, format(listFreq[idx], '4'), format(dFreq, '4d)) def test(): print(' Testing with input file assign01.txt testoneFile('assign01. txt') print(" Testing with empty input file ...) testoneFile('assigne1_test_empty.txt') print(" Testing with input file containing only special characters testone File('assign01_test_noletters.txt) print(" Testing with input file containing: frequency of 1 for each letter testOneFile('assign01_test_allFrequenciesArgone.txt') print(" Testing with input file containing ascending sequence of frequencies ...) testOneFile('assign01_test_frequenciesAscending txt') def testOneFile(fileName) : listFrea [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] dictFreq = {} inFile = openFile(fileName) countLetters(inFile, listFreg, dictFreq) display (listFreq, dictFreq) inFile.close() test)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
