Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WHAT SHOULD THIS PROGRAM DO? Youre given a list of words that appear in a collection of works by William Shakespeare, and the number of

WHAT SHOULD THIS PROGRAM DO? Youre given a list of words that appear in a collection of works by William Shakespeare, and the number of times each words appears in the collection. Your program will sort an array of those words by their number of occurrances in ascending order using Insertion Sort, then descending order using Reverse Bubble Sort, and then ascending order again using Quicksort. For each sort algorithm, the algorithm will be timed and the number of seconds will be printed to the screen. Also, for each sort algorithm, the data will be printed to a text file. Driver.cpp is partially provided for you. This is the file that contains the main function. You will be adding all the necessary programmer-defined functions to Driver.cpp to accomplish the sorting algorithms. You should not have to write or modify code in the other given files!! The Timer class (Timer.h & Timer.cpp) is provided for you. This is the class that is used in the Driver.cpp file to time the algorithms. HOW TO TEST YOUR PROGRAM Compile your program with g++ Timer.cpp Driver.cpp. You must test your program with four different text files, which I have provided: 5words.txt (5 words from the list), 100words.txt (100 words), words_half.txt (roughly half the list of words), and words_full.txt (ever word in this collection of data). You will be making a screenshot of each of these four tests successfully running. These images should be part of your submission. You can either place the images in one document file or submit them as three different image files. As long as we can see that you were able to successfully run the three tests described below. FIRST TEST: SAMPLE OUTPUT This is sample output for the first test, with 5 words. Run this first to check your code, then make sure to run all four tests and screenshot the output. Five words are sorted quickly enough that they take less than a second to run, but the bigger files will start to take longer. Which file are you opening? 5words.txt Youve read in in 5 words. Insertion sort: 0 seconds Reverse bubble sort: 0 seconds Quicksort: 0 seconds WHAT TO TURN IN Zip the following files in a single zip folder and upload to the Lab 3 Submission Folder. Driver.cpp Timer.cpp Timer.h 5words.txt 100words.txt words_half.txt words_full.txt screen captures of your program running four different times using the four files. Driver.cpp #include "Timer.h" #include #include using namespace std; struct wordCount{ string word; int count; }; void insertionSort(wordCount *wordArray, int numWords); void bubbleSortReverse(wordCount *wordArray, int numWords); void quicksort(wordCount *wordArray, int low, int high); int partition(wordCount *wordArray, int left, int right); int main() { wordCount* wordArray = new wordCount[150000]; int numWords = 0; string temp; int num; ofstream outfile; ifstream infile; time_t start, end; char filename[50]; cout << " Which file are you opening? "; cin >> filename; infile.open(filename); if(!infile) { cout << " Sorry, I couldn't find that file. "; return 1; } while(getline(infile, temp) && numWords != 150000) { wordArray[numWords].word = temp; infile >> num; infile.ignore(); wordArray[numWords].count = num; numWords++; } cout << "you've read in " << numWords << " words. "; //sort the songs using insertion sort and print them out to the text file sortFileInsertion.txt start = getTime(); //Starts timer. //LOOK!!!! CALL THE INSERTION SORT ALGORITHM HERE end = getTime(); //Ends timer. outfile.open("sortFileInsertion.txt"); cout << " Insertion sort: " << totalTime(start, end) << " seconds "; for(int x=0; x #include #include /* Pre: None Post: Returns the current system time */ time_t getTime(); /* Pre: start and end are variables of type time_t containing 2 different system times, start is before end Post: Will return the number of seconds separating two times */ double totalTime (time_t start, time_t end);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions