/* ptrLab.cpp Name: CIS 150 Date: CIS 150 Pointer Lab */ /* Place your name and section at the top in comments. Read the instructions for each section and then implement your solution within this program. */ #include #include #include #include using namespace std; // 1. Create prototypes for the four functions described at the end of this lab. void checkFile(const char* fname); int main(int argc, char** argv) { const int SIZE = 25; int sum; // 2. Dynamically create an array of ints with SIZE elements named: array // 3. Call fillArray to fill the array with random ints from 1 - 100 // 4. Call displayArray to print the elements of array on the screen. // 5. Call sumArray to get the sum of the elements of the array and store that value in sum. cout << "The sum of the array is " << sum << '\n'; // 6. Open a file for sequential text output. The file name is nums.txt // 7. Call writeArray to store the elements in that file. // 8. Close that file. // 9. Release the memory you allocated for the array. checkFile("nums.txt"); return 0; } void checkFile(const char* filename) { int numRecs = 0; int sum = 0; int num; ifstream infile(filename); if (!infile) { cout << "Error reading file" << endl; } else { infile >> num; while (!infile.eof()) { sum += num; numRecs++; infile >> num; } } infile.close(); cout << "Records in file: " << numRecs << endl; cout << "Sum of records in file: " << sum << endl; } // Create the following functions: // 1. fillArray // input: a pointer to an int array and an int length of the array // output: nothing // effect: fills the array with random ints between 1 and 100 // // 2. displayArray // input: a pointer to an int array and an int length of the array // output: nothing // effect: displays the elements of the array on stdout with a space separator // with a newline after all the elements are printed // // 3. writeArray // input: a reference to an ofstream object, a pointer to an int array, // and an int length of the array // output: nothing // effect: writes the elements of the array to the specified file with a // newline after each element // // 4. sumArray // input: a pointer to an int array and an int length of the array // output: returns the sum of the integers in the array //