Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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 .
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 ROSE11. 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started