Hello, I'm working a programming problem for class. Need help.
Prompt the user for the name of an input file. Open and read the first line of this user-specified input file. Create a double array with a size to match the first line of the input file. So this means that if the first line of the input file is a 100, the array will have 100 slots. If the first line of the input file is a 200, the array will have 200 slots. This means that the array must be dynamically sized according to the first line read from the file. Your program should then read the remaining numbers into the array. Once the array has been filled, sort the array from low to high. After the sort is complete, use a loop to sum the elements in the array, and then calculate the average of all values within the array. Prompt the user for the name of an output file. Open this user-specified output file and write the following information to this file: the number of slots in the array, followed by the sorted list of numbers (one per line), and finally, the average value within the array. Use the provided scores.dat test data file to get your program working. scores.dat
10
90.5
100
89.9
80.10
79.95
70
69
60.5
59.0
0.0
#include <stdafx.h>
#include <iostream>
#include <fstream>
#include <cstdlib> // needed for exit()
#include <string>
usingnamespace std;
int main()
{
// program goes here
string filename;
ifstream inFile;
cout << "Please enter the name of the file you wish to open: ";
cin >> filename;
inFile.open(filename.c_str()); // open the file
if (inFile.fail()) // check for successful open
{
cout << "\nThe file named " << filename
<< " was not successfully opened"
<< "\n Please check that the file currently exists."
<< endl;
cin.ignore();
exit(1);
}
cout << "\nThe file has been successfully opened for reading.\n";
cin.ignore();
return 0;
}
void sort(double nums[], int numels)
{
// sort function
}