Assignment (8)

CS 1440 - Due Nov. 1

Write a program which reads a list of integers from a user-specified input file  and outputs the list with duplicates removed to a user-specified output file. That is, any value which occurs at least once in the input file should occur once and only once in the output file and that the position of occurrence will be determined by the relative positive of the first occurrence in the original input file. You may assume that there are no more than 100 numbers in the input file. This means that you should allocate space for 100 numbers as in
int data[100];
but keep track of the actual numbers read.
For example, suppose that the input file contains these values:
2  8  3  4  6  8  2  1 4  1  1  1 6  5  5
the output file with duplicates removed should be
2  8  3  4  6  1 5
Here are the function prototypes for the functiuons that you are required to use:
void open_input_file(ifstream &input_file);
// Prompts the user for the name of the input file
// and attempts to open the file.
// If the file cannot be opened successfully, the user
// is given two options:
//  - try another file name
//  - exit the program

void open_output_file(ofstream &output_file);
// Prompts the user for the name of the output file
// and attempts to open the file.
// If the file cannot be opened successfully, the user
// is given two options:
//  - try another file name
//  - exit the program

void read_array_data(ifstream &input_file, int data[], int & data_size);
// Reads integer data from the input file stream and stores sequentially
// in the array data[].  Input halts at the end of file or when the
// array is filled, in which case all other data in the file is
// ignored.  This function returns the actual number of values stored
// in the array data[] by changing the parameter data_size.

void save_array_data(ifstream &output_file, int data[], int data_size);
// Write integer data from the array data[] to the output file stream.
// The parameter data_size specifies the number of items to be written.
// It is required that data_size be <= the actual array size.

void remove_duplicates(int data[], int & data_size);
// Removes all duplicate elements from the integer array data[].
// The value of data size will be reduced if duplicates are removed.
// It is required that data_size be <= the actual array size.

void find_duplicate position(int data[], int data_size, int element_index,
                            int search_index);
// This function searches the integer array data for a duplicate
// of the item data[element_index] starting the search at search_index
// through index data_size-1.  The index of the first duplicate
// found is returned as the modified search_index.  If no duplicates are
// found OR if search_index is <= element_index, then -1 is returned as
// the value of search_index.
// It is required that data_size be <= the actual array size.

void remove_item(int data[], int & data_size, int remove_index);
// Removes the item at position remove_index and moves all
// subsequent elements one position forward.  If remove_index
// is negative or greater than data_size-1, the array is
// not changed.  The data_size is decremented if an item is removed.
// It is required that data_size be <= the actual array size.