Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Part 01 - Sorting a Text File Write a program that will open up the provided text file of words named shuf fled.txt, reads

Assignment Part 01 - Sorting a Text File Write a program that will open up the provided text file of words named shuf fled.txt, reads in each word into an array and sorts the array. Write the sorted array of words out to a file named sorted.txt . Time your program to figure out how long it takes to sort the words. Part 02 - Searching Sorted Words Once sorted, how many words away is megaloblastic from impiety? Print it out to the screen (dont figure this out by hand, make the program figure it out for you). Time your program to figure out how long it takes to search for these words. Note Youll have to read in the text file into an array, then sort the array. To time your program use clock_t from the ctime standard library. This calculates clock ticks and not seconds, dont worry well discuss how to calculate time in seconds. Make sure you print out the elapsed time it took to sort your array (the time taken to fill the array initially not included). You dont need to come up with your own sorting algorithm. Use the sort() function from the algorithm standard library. Extra Credit Opportunity After youve completed everything else, go back and implement your own sorting algorithm. Only this time make sure you dont read in the entire text file. Limit yourself to only the first 4,000 words. Make sure your program executes in 10 seconds or less. You may want to separate out your functions into a header file. Feel free to ask me for assistance, especially during office hours. Final Notes Test your program to make sure it works with different values. Submit your source code on Titanium. Make sure you comment your header with your name, your partners name (if you had one) which class and section youre in, and a simple description at the top. If you attempted the extra credit, make sure you indicate so in the top header. Make sure your submitted file is named: lastname_hw04.cpp // Skeleton Code #include #include using namespace std; int main() { // Part One // Read in file clock_t begin = clock(); // Sort the words clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; // Write out sorted words to file // Output the elapsed time // Part Two begin = clock(); // Search for the two words end = clock(); elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; // Output how far apart the two words are // Output the elapsed time return 0; }

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

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions