Part A

Purpose: To learn to implement Sorted Linked Lists and to use a test driver.

Problem: Your goal in this assignment is to implement the modified Sorted Linked List attached to this assignment. Read the comments carefully!!! You will then implement the printList non-member function in the main program to demonstrate that you know how to call the methods of Sorted Linked List. You will then compile and run the test driver project.

Input: There is one data file for Part a. Your program prompts for the filename and opens it.

Output: The test driver will output what you should get and you should verify that you get that.

Part B

Purpose: To learn to use Sorted Linked Lists; to learn more about creating and using classes and objects; to learn more about reading from multiple files and printing to a file

Problem: Your goal in this assignment is to write a program that counts the number of times words occur in a set of files. To do this, use an array of sorted linked lists (that is youll have 26 linked lists - one for each letter of the alphabet) to store strings, along with the number of times each string occurs in each file you've scanned. After scanning all of the files, your program will print out a list of all the words that were contained in the files, along with the number of times each word appeared in all the input files.

Input: There may be more than one file used as input. Your program should prompt the user for the name of a file from the keyboard and open the file as input. Read from that file, process the words, and then close that file. Then prompt the user, asking if there is another file to be used for input, read from that file, process the words, and then close that file and so on. So main will have a loop!

It's not an error to be asked to read the same file two or more times. Also, if all files contain no words (for example, every file contains only blanks), simply print a message saying No words read.

Method: For each file, your program should count the number of words in the file and store the count for each word in a Word node (a class with public member data) in a sorted linked list. There are 26 linked lists, one for each letter of the alphabet, each kept in sorted order. Combined the lists contain all of the words seen in any file to this point, and each word must track the number of times it has occurred in the files scanned to that point.

A word must meet the following criteria:

  • It starts with a letter (A-Z)
  • It contains only letters
  • It ends with a space, end of the line, or end of the file.
  • The file will contain no punctuation and no small letters.

As mentioned above, your code should use an array of sorted linked lists, one for each letter of the alphabet. This means you'll need to implement a sorted linked list class as well as a class that defines the storage for a single word and its count.

You should keep your linked lists sorted; you can use the compare method from the string library to compare two strings to see which is alphabetically later.

s1.compare(s2) Returns a signed integral indicating the relation between the strings:

value = relation between compared string and comparing string
0 = They compare equal
< 0 = Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
>0 = Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.

Example: if s1 = apple and s2 = peach s1.compare(s2) returns -1.

You may use s.at(0) to get the first character within the string. If you want to use the first element in the array for the list of the 'a' strings, the second for the 'b' strings, and so on, you can convert 'a' into 0, 'b' into 1, and so on by doing the following:

int index = toupper(s[0]) – 65; //65 is the ASCII code for 'a'

HINTS:

  • Use infile >> s; to get words from the file. The >> operator gets characters up to whitespace.
  • Make sure you get your sorted linked list working and test it with the driver in part A.
  • Count every word that is read.

Output: Output goes to a file. Print a heading, print the names of the files, the total number of words from each file, the grand total of all words and then all words found in alphabetical order with their frequency counts.

For example,

Catherine Stringfellow
Program 4 Word Count

Files: Data1.txt 40 words
Data2.txt 100 words

Words:
A 5
CAR 3
CHEVY 1
I 2
IN 3
OR 2
RIDE 1
SO 1
THAT 1
THE 2
THOUGHT 1
TIME 1
TO 3
WAS 2
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.