Question: You are to write a program that reads sales data from a text file, sorts the data and outputs the sorted data to a second

You are to write a program that reads sales data from a text file, sorts the data and outputs the sorted data to a second file. The input file is a comma-seperated value file (CSV), with the first item being the number of sales data items to be processed, followed by the list of sales data on one line (items are seperated by commas). Each sales data item is decimal number.

Your program should have at least three functions, in addition to function main():

a function (getSalesData) to read the sales data form the input file and store it in an array of the appropriate size. Since the number of data items will vary from one program execution to another, you want to use a dynamic array to store the sales data. In function main() open the input file, read the number of sales data items, create a dynamic array of the proper size then call function getSalesData with the name of the array, its size, and the input file stream variable as paramters. Function getSalesData when called, reads the sales data items from the input stream parameter into the array. Remember that array are always passed by reference.

a function to sort the data in ascending order. You may use the selection sort function from the previous lab.

a function to write the sorted data into the output file. Note: output file should have the same format as the input file except that the sales data is sorted (i.e. first line has the number of data items followed by sales data values separated by commas).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!