Question
Write a C++ program that processes a string data file. The program will 1) read the names from a string data file and place them
Write a C++ program that processes a string data file. The program will 1) read the names from a string data file and place them in an array, and 2) sort the names in the array in ascending order using selection sort. The program will use a function to display the array before it is sorted and AFTER it is sorted. A separate function should be implemented to save the sorted names to a data file called sortedNames.txt. Project Specifications Input for this project: you may use the attached data file names.txt for testing, or a string data file of your own. Assume the file contains at least 20 names, each written on a separate line. The user must enter the number of names to process and names of the input file and output file. Output: If the input file does not open, an error message should appear on the console. The program should have the follow output: Display the names in the array before sorting (unsorted list) Display the names in the array after sorting (sorted list) Save the sorted array to a data file Processing Requirements Define all functions after main function and prototype them properly. Assume that the data file contains 20 names on separate lines and is constructed correctly. Create functions for the following: 1. Read the names from the data file: Prompt for and get the input file name and try to open the file. If the file opens, read the names from the file, store them into the array. If the file does NOT open, print an error message on the console. If the file is not found, do NOT process the names. 2. Display the unsorted array. The string array should be a parameter. 3. Display the sorted array. The string array should be a parameter. 4. Save the sorted array to a data file. Prompt the user for data file name. The string array should be a parameter. Sample Input File: 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 Sample Output File: Names in Ascending Order: Allen, Jim, Allison, Jeff Collins, Bill Griffin, Jim Harrison, Rose Holland, Beth James, Jean Javens, Renee, Johnson, Jill, Looney, Joe Pike, Gordon Pore, Bob, Rose, Geri, Rutherford, Greg Setzer, Cathy, Smith, Bart Stamey, Marty Taylor, Terri Weaver, Jim Wolfe, Bill,
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