Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

String Selection Sort Modify the selectionSort function presented in this chapter so it sorts an array of strings instead of an array of int s.

String Selection Sort Modify the selectionSort function presented in this chapter so it sorts an array of strings instead of an array of int s. Test the function with a driver program. Use Program 8-8 as a skeleton to complete. Program 8-8 #include #include using namespace std; 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" }; // Insert your code to complete this program return 0; }

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.

Create a function to count how many last names begin with each letter and output the names and the total number of names each time (see Sample Output below). This function should be passed the array by value and the size of the array by value. The function should output the names that begin with a particular letter then output the total number of names. Do NOT output results for letters that do not have any names, i.e. for example ther are no names that begin with B, so no output should be generated for this letter.

NO GLOBAL VARIABLES ALLOWED.

Read Names from an input file called names.txt. Names data:

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

 

Write the result of your selection sort to the screen.

Use functions to read in the names from the file, to display the names in the array and to sort the names in the array. In addition create a function to count how many last names begin with each letter and output the results clearly!!!

Hint: When reading in the names from the file you will want to use the getline() function. If you use the >> operator to read in the data from the file you will not be reading in the whole name (try it and see what happens).

Pseudo Code for main function:

Declare and Initialize Variables.

Call the function to Read in the names from the input file names.txt

cout << "Here are the unsorted names: ";

cout << "-------------------------- ";

Call the function to display the array.

Call the function to sort the array.

cout<<"Here are the names sorted: ";

cout << "-------------------------- ";

Call the function to display the array.

Call the function to count how many names begin with each letter.

NO GLOBAL VARIABLES ALLOWED.

Read Names from an input file called names.txt. Names data:

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

 

Write the result of your selection sort to the screen.

Use functions to read in the names from the file, to display the names in the array and to sort the names in the array. In addition create a function to count how many last names begin with each letter and output the results clearly!!!

Hint: When reading in the names from the file you will want to use the getline() function. If you use the >> operator to read in the data from the file you will not be reading in the whole name (try it and see what happens).

Pseudo Code for main function:

Declare and Initialize Variables.

Call the function to Read in the names from the input file names.txt

cout << "Here are the unsorted names: ";

cout << "-------------------------- ";

Call the function to display the array.

Call the function to sort the array.

cout<<"Here are the names sorted: ";

cout << "-------------------------- ";

Call the function to display the array.

Call the function to count how many names begin with each letter.

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions