Computer sciences and Information technology
CS 120 Project 5 – Files, Classes, and Objects
Fall 2014 – due Mon Nov 24
Write Python programs that involve files, classes and objects. The programs involving files should have most of the file processing activities encapsulated in a
separate function. Each class definition with its member variables and methods should be in its own file.
1. Input text data from a file: The main program should allow the user to choose a data file. The program should then open the file for reading. Input the
contents of the file into a single string S, and then close the file..
Your main program should next have the user input a single word W (e.g. “who”). The program should call the function countWord(S,W), which will return the number of
occurrences of word W in string S. The count should be case insensitive, so convert string S and word W to lower case before performing the word count. Note that W
sometimes may be part of a longer word, which increases the count.
Output the word (in lower-case) along with the search frequency. For each of the files listed below, run your program for all of the following words (one word at a
Words: the, and, he, she, his, her
Files: (a) DeclarationOfIndependence.txt
2. More text file analysis: The main program should allow the user to choose a data file. The program should then open the file for reading. Input the contents of
the file into a single string S, and then close the file.
Your main program should next have the user input a single word W with no repeating characters (e.g. “abcXYZ”). The program should call the function countChars(S,W).
This function will return a list F containing frequencies for each character in W. The frequencies in the list should appear in the same order as the characters in W.
The counts should be case insensitive, so convert string S and word W to lower case before performing the character counts.
Output each character in word W paired with the frequency for that character. Run your program for the following test cases:
(a) File: RoadNotTaken.txt Word: “TRaeiou”
(b) File: IfByKipling.txt Word: “YFaeiou”
(c) File: Jabberwocky.txt Word: “JBaeiou”
3. Encryption string class: Write a Python class called EString to implement a class of strings that can be encrypted and decrypted. The class has two private
(a) a string W that represents the string to be encrypted or decrypted.
(b) an integer variable K that is the key to be used to encrypt or decrypt the string.
Write code for the following public methods in this class:
(1) A constructor EString(W) that creates an EString object S and sets the first member variable to the lower-case version of string W. The initial key value is
set to 0.
(2) A S.setKey(K) method that sets the key value to integer K (-25 <= K <= 25). (3) A S.encrypt() method that returns an encrypted version of string S, using the current value of key K. The encryption algorithm is a Caesar cipher with shift K. Only lower-case letters are encrypted by the cipher. Note: This method can be used to both encrypt (using K) and decrypt (using –K). 4. Encryption strings: Write a Python test program that demonstrates the methods of the EString class. Input a string W and a key value K. Then create an EString object S1. Perform the following encryption and decryption activities: (1) Encrypt your string using key K. Call the resulting string S2. (2) Then decrypt string S2 using key – K. Call the result S3. Your test program should then output strings S2 and S3. Run your test program for the following cases, and display the results. (a) W = Have a nice day! K = 3 (b) W = I love dark chocolate. K = 5 (c) W = My password is “meatballs”. K = -8 (d) W = We attack the enemy at dawn! K = 17 PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT ?
Our Service Charter
Excellent Quality / 100% Plagiarism-FreeWe employ a number of measures to ensure top quality essays. The papers go through a system of quality control prior to delivery. We run plagiarism checks on each paper to ensure that they will be 100% plagiarism-free. So, only clean copies hit customers’ emails. We also never resell the papers completed by our writers. So, once it is checked using a plagiarism checker, the paper will be unique. Speaking of the academic writing standards, we will stick to the assignment brief given by the customer and assign the perfect writer. By saying “the perfect writer” we mean the one having an academic degree in the customer’s study field and positive feedback from other customers.
Free RevisionsWe keep the quality bar of all papers high. But in case you need some extra brilliance to the paper, here’s what to do. First of all, you can choose a top writer. It means that we will assign an expert with a degree in your subject. And secondly, you can rely on our editing services. Our editors will revise your papers, checking whether or not they comply with high standards of academic writing. In addition, editing entails adjusting content if it’s off the topic, adding more sources, refining the language style, and making sure the referencing style is followed.
Confidentiality / 100% No DisclosureWe make sure that clients’ personal data remains confidential and is not exploited for any purposes beyond those related to our services. We only ask you to provide us with the information that is required to produce the paper according to your writing needs. Please note that the payment info is protected as well. Feel free to refer to the support team for more information about our payment methods. The fact that you used our service is kept secret due to the advanced security standards. So, you can be sure that no one will find out that you got a paper from our writing service.
Money Back GuaranteeIf the writer doesn’t address all the questions on your assignment brief or the delivered paper appears to be off the topic, you can ask for a refund. Or, if it is applicable, you can opt in for free revision within 14-30 days, depending on your paper’s length. The revision or refund request should be sent within 14 days after delivery. The customer gets 100% money-back in case they haven't downloaded the paper. All approved refunds will be returned to the customer’s credit card or Bonus Balance in a form of store credit. Take a note that we will send an extra compensation if the customers goes with a store credit.
24/7 Customer SupportWe have a support team working 24/7 ready to give your issue concerning the order their immediate attention. If you have any questions about the ordering process, communication with the writer, payment options, feel free to join live chat. Be sure to get a fast response. They can also give you the exact price quote, taking into account the timing, desired academic level of the paper, and the number of pages.