Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Challenge: 11 - String Selection Sort Modification Modify the program you wrote for Programming Challenge 6 so it reads in the 20. strings from

Programming Challenge: 11 - String Selection Sort Modification

Modify the program you wrote for Programming Challenge 6 so it reads in the 20. strings from a file.

Have the program prompt the user for the file name.

Submit a copy of your input file if you write your own.

#include #include using namespace std;

void selectionSort(string[], int); void printArray(string[], int);

int main() { const int NUM_NAMES = 20; string names[NUM_NAMES] = {"Collins, Bill", "Smith, Bart", "Allen, Jim", "Griffin, Jim", "Stamey, Marty", "Rose, Geri", "Taylor, Terri", "Johnson, Jill", "Allison, Jeff", "Looney, Joe", "Wolfe, Bill", "James, Jean", "Weaver, Jim", "Pore, Bob", "Rutherford, Greg", "Javens, Renee", "Harrison, Rose", "Setzer, Cathy", "Pike, Gordon", "Holland, Beth"}; cout << "Names before sorting:" << endl << endl; printArray(names, NUM_NAMES);

selectionSort(names, NUM_NAMES);

cout << " Names after sorting:" << endl << endl; printArray(names, NUM_NAMES);

return 0; }

void selectionSort(string strArray[], int size) { int startScan, minIndex; string minValue;

for (startScan = 0; startScan < (size - 1); startScan++) { minIndex = startScan; minValue = strArray[startScan];

for (int index = startScan + 1; index < size; index++) { if (strArray[index].compare(minValue) < 0) { minValue = strArray[index]; minIndex = index; } }

strArray[minIndex] = strArray[startScan]; strArray[startScan] = minValue; } }

// printArray function implementation void printArray(string strArray[], int size) { for (int index = 0; index < size; index++) { cout << strArray[index] << endl; } cout << endl; }

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago