QuestionQuestion

Consider the files StringSorterV1.py, StringSorterV2.py StringSorterV3.py, and StringSorterV4.py that each present a complete and valid Python method named StringSorter.
Each of these performs the task specified in Section 1.1 and developed in Chapter 1 of the Essentials of Software Engineering text, and are further illustrated in the Python for Chapter 1 document.

For this assignment, you are to first test the operation of each of these modules with multiple text files to familiarize yourself with them and to convince yourself that they work.
If you discover that one or more of these implementations does not work correctly then you are to prepare a document in which you illustrate (through screen shots) and explain representative cases that fail.

Next, you are to modify each of these implementations (progressing from version 1 through version 4) so that blank lines in the input are ignored in the result.
Please do not change the name of the methods, but do rename your modified files by appending an ‘R’ to each filename; thus StringSorterV1.py becomes StringSorterV1R.py, etc.

Along with submitting these four Python source code files, you are to prepare and submit a single document in which you illustrate (through screen shots) the execution of your revised implementations, with accompanying narrative explanations as appropriate.

Additional and Optional:

Improving the operation of the StringSorter implementations may be accomplished by developing a Python function to compare two strings rather than relying directly upon Python’s intrinsic operators to compare strings.

Such a function could then implement its own algorithm to compare two strings interpreting lower and uppercase in a more natural way. Consider the following table that presents the strings from stringsC.txt in their original order and also in the order obtained by having Microsoft Word sort them. This result is considered to be such a more natural ordering and you are to develop your algorithm

# StringSorterV1.py
# -----------------

def StringSorter(inputFileID, outputFileID):
inputFile = open(inputFileID,"r")
lines = inputFile.readlines()
inputFile.close()
lines.sort()
outputFile = open(outputFileID,"w")
for line in lines:
outputFile.write(line)
outputFile.close()

#2

# StringSorterV2.py
# -----------------

def StringSorter(inputFileID, outputFileID):
inputFile = open(inputFileID,"r")
lines = []
for line in inputFile:
lines.append(line)
inputFile.close()
lines.sort()
outputFile = open(outputFileID,"w")
for line in lines:
outputFile.write(line)
outputFile.close()
#3
# StringSorterV4.py
# -----------------

def getStrings(inputFileID):
result = []
inputFile = open(inputFileID,"r")
for line in inputFile:
result.append(line)
inputFile.close()
return result


def putStrings(strings, outputFileID):
outputFile = open(outputFileID,"w")
for string in strings:
outputFile.write(string)
outputFile.close()


def findIndexOfBiggest(strings, fromIndex, toIndex):
result = fromIndex
for index in range((fromIndex+1),(toIndex+1)):
if(strings[index] > strings[result]):
result = index
return result


def swap(strings, index1, index2):
temporary = strings[index1]
strings[index1] = strings[index2]
strings[index2] = temporary


def sortStrings(strings):
for index in range((len(strings)-1),0,-1):
indexOfBiggest = findIndexOfBiggest(strings,0,index)
swap(strings,index,indexOfBiggest)


def StringSorter(inputFileID, outputFileID):
lines = getStrings(inputFileID)
sortStrings(lines)
putStrings(lines,outputFileID)

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# StringSorterV4R.py
# -----------------

def getStrings(inputFileID):
    result = []
    inputFile = open(inputFileID,"r")
    for line in inputFile:
       result.append(line)
    inputFile.close()
    return result


def putStrings(strings, outputFileID):
    outputFile = open(outputFileID,"w")
    for string in strings:
       if len(string.strip()) > 0...

By purchasing this solution you'll be able to access the following files:
Solution.docx, StringSorterV1R.py, StringSorterV2R.py, StringSorterV3R.py, StringSorterV4R.py, input.txt, input2.txt, output.txt and output2.txt.

$50.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats