Question: #include #include #include using namespace std; // Function prototypes void selectionSort(string[], int); void displayArray(string[], int); int main() { const int SIZE = 20; string name[SIZE];
| #include | |
| #include | |
| #include | |
| using namespace std; | |
| // Function prototypes | |
| void selectionSort(string[], int); | |
| void displayArray(string[], int); | |
| int main() | |
| { | |
| const int SIZE = 20; | |
| string name[SIZE]; | |
| ifstream Read; | |
| Read.open("names.dat"); | |
| if (!Read) | |
| cout | |
| else | |
| { | |
| for (int i = 0; i | |
| { | |
| getline(Read, name[i]); | |
| } | |
| // Call the selectionSort function | |
| selectionSort(name, SIZE); | |
| // Call the displayArray function | |
| displayArray(name, SIZE); | |
| } | |
| Read.close(); | |
| return 0; | |
| } | |
| /********************************************************************************* | |
| * selectionSort * | |
| * This function uses the selection sort to arrange the values in a string array * | |
| * in ascending order * | |
| *********************************************************************************/ | |
| void selectionSort(string array[], int size) | |
| { | |
| int startScan, minIndex; | |
| string minValue; | |
| for (int startScan = 0; startScan | |
| { | |
| minIndex = startScan; | |
| minValue = array[startScan]; | |
| for (int index = startScan + 1; index | |
| { | |
| if(array[index] | |
| { | |
| minValue = array[index]; | |
| minIndex = index; | |
| } | |
| } | |
| array[minIndex] = array[startScan]; | |
| array[startScan] = minValue; | |
| } | |
| } | |
| /********************************************************************************* | |
| * displayArray * | |
| * This function displays all the values in the array. * | |
| *********************************************************************************/ | |
| void displayArray(string name[], int size) | |
| { | |
| for (int i = 0; i | |
| { | |
| cout | |
| } | |
| } Copy and modify your selection sort code to use vectors (See Gaddis, Program 8-7, p. 496), then repeat Programming Challenge 8.11. |
If you want information from textbook, ask in comment and I will post it .
![#include #include #include using namespace std; // Function prototypes void selectionSort(string[],](https://s3.amazonaws.com/si.experts.images/answers/2024/07/66a51d8ac940a_03466a51d8a737a8.jpg)
name.txt:
MARY PATRICIA LINDA BARBARA ELIZABETH JENNIFER MARIA SUSAN MARGARET DOROTHY LISA NANCY KAREN BETTY HELEN SANDRA DONNA CAROL RUTH SHARON MICHELLE LAURA SARAH KIMBERLY DEBORAH JESSICA SHIRLEY CYNTHIA ANGELA MELISSA BRENDA AMY ANNA REBECCA VIRGINIA KATHLEEN PAMELA MARTHA DEBRA AMANDA STEPHANIE CAROLYN CHRISTINE MARIE JANET CATHERINE FRANCES ANN JOYCE DIANE ALICE JULIE HEATHER TERESA DORIS GLORIA EVELYN JEAN CHERYL MILDRED KATHERINE JOAN ASHLEY JUDITH ROSE
![int); void displayArray(string[], int); int main() { const int SIZE = 20;](https://s3.amazonaws.com/si.experts.images/answers/2024/07/66a51d8b61f5c_03566a51d8b0428f.jpg)
11. Using Files-String Selection Sort Modification Modify the program you wrote for Programming Challenge 6 so it reads in 20 strings from a file. The data can be found in the names.txt file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
