C program that processes a string data file the program


  • Working with arrays
  • Using file operations
  • Using a selection sort to sort string arrays
  • Using a function to display arrays
  • Using a function to save arrays to file
  • Implementing functions besides function main()

Project Description

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 four functions for the following:

1. Function 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. The function accepts two arguments: array of string and array size

2. Function Display the unsorted array. The function accepts two arguments: array of string and array size 

3. Function Display the sorted array. The function accepts two arguments: array of string and array size 

4. Function Save the sorted array to a data file. Prompt the user for data file name. The function accepts two arguments: array of string and array size

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,

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: C program that processes a string data file the program
Reference No:- TGS02774423

Now Priced at $10 (50% Discount)

Recommended (91%)

Rated (4.3/5)