Question: C++(Code::Block or Visual Studio) You are given a txt file called word.txt with unordered words. You are asked to write a program that would create

C++(Code::Block or Visual Studio)

You are given a txt file called word.txt with unordered words. You are asked to write a program that would create a new file with the same words but sorted alphabetically.

You must have 4 functions other than main.

1. int getNumLines(const string & inputFName)

This function receives the name of the file, opens it, and returns the number of lines in the file.

2. string* createArr(const string & inputFName, )

This function receives the name of the file and creates an unordered string array in the heap. It returns a pointer to the created array.

3. void insertionSort(string arr[], int size)

This function receives the array and its size and sorts the array in ascending order.

4. void writeToFile(string arr[], int size, const string &outputFName)

This function receives the array, the size, and string. It creates a new file with the words after they are sorted alphabetically.

5. main()

- Prompts the user to enter the names of the two files.

- Calls getNumLines

- Calls createArr

- Calls insertionSort.

- Calls writeToFile.

- Calculates the execution time the insertion sort takes to sort the array.

- Use the following:

clock_t start = clock(); //start timer

//call the insertionSort

double endTime = static_cast(clock() - start) / CLOCKS_PER_SEC; // ending time.

Sample run:

enter the name of the file to read from:words.txt

enter the name of the file to write to after sorting:input.txt

Insertion sort took: 105.567 seconds

Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!