Answered step by step
Verified Expert Solution
Link Copied!

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 .

image text in transcribed

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

image text in transcribed

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

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

=+Why were they effective? How could you continue the campaign?

Answered: 1 week ago

Question

=+Who's your primary audience?

Answered: 1 week ago

Question

=+What do they need to hear?

Answered: 1 week ago