Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ sorting, http://pastebin.com/VaN7Ybgh document passed in (contains words). T

ID: 662132 • Letter: C

Question

C++ sorting, http://pastebin.com/VaN7Ybgh document passed in (contains words).

This lab involves implementing 3 sorting algorithms: Selection sort, one of the following 3 algorithms: Bubble, Insertion, or Shell sort, and one of the following: Quicksort or MergeSort. All of these algorithms can be found all over the web. I will assume that A: you understand each algorithm well enough to implement it on your own in a crunch, and B: you found the code on the internet and are using that. These days, we often want to automatically identify and classify documents based on their overall topic. For instance, search engines may wish to know what the topic of a document is in order to bring up more relevant documents during searches. One way to identify the topic of a document is to look at how similar a document is to other documents on that particular topic. We can do this by looking at the words in the document, and in particular, the content words that occur the most frequently. So for this lab, you will read in the 5 documents provided, each into an array of words. You will use the time class to create a time object right before you sort each document array, and then create another time object right after. You will sort each document, using each of the 3 sorting algorithms. You will then print out which sorting algorithm was quickest for each of the 5 documents. Print out the arrays to be sure that they are sorted properly. The time class creates a time object (down to the millisecond) that is printed out as follows: struct timeval tp; gettimeofday(&tp;, NULL); long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000; cout x; if (!file.eof()) { ct++; } } file.close() ; doc.length = ct; ifstream file2(doc.filename.c_str()); ct = 0; while (!file2.eof()) { file2 >>x; if (!file2.eof()) { doc.arr[ct] = x; ct++; } } file2.close(); return; }

Explanation / Answer

#include 02 #include 03 #include 04 #include 05 #include 06 #include 07 #include 08 09 void erase_duplicates(void); 10 long int hm(void); 11 12 int main(void) 13 { 14     erase_duplicates(); 15     return 0; 16 } 17 18 void erase_duplicates(void) 19 { 20     FILE *p, *po; 21     char w[50]={0}, ww[50]={0}; 22     long int i=0, j=0, duplicate_word=0; 23 24     po=fopen("SortedWords","w"); 25     fclose(po); 26     p=fopen("Words","r"); 27     fscanf(p, "%s", &w); 28     i=1; 29     po=fopen("SortedWords","a"); 30     do 31     { 32         duplicate_word=0; 33         do 34         { 35             fscanf(p, "%s", &ww); 36             if(strcmp(w,ww)==0) 37             { 38                 duplicate_word=1; 39             } 40         }while(ww[0]!='*' && duplicate_word!=1); 41         i++; 42         if(!duplicate_word) 43         { 44             fprintf(po, "%s ",w); 45         } 46         fclose(p); 47         p=fopen("Words","r"); 48         for(j=0;j
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote