// pgm30 // examples of functions that accept arrays as parameters // 11/16/2016 #include #include #include #include using namespace std; void displayArray(double[], int); int readinArray(double[]); void addTwoArrays(double arr1[], double arr2[], double answer[], int n); const int SIZE=25; int main() { // allocate an array of size SIZE double idnums[SIZE], numelts=0; //initialize an array with { } double prices[SIZE], taxes[SIZE]={3.2, 4.1, 1.8, 9, 5.6}; double total[SIZE]; // function call to read values into the array numelts = readinArray(idnums); // function call to display the elts in the array displayArray(idnums, numelts); // now call readinArray with the prices array numelts = readinArray(prices); cout << "Prices:"; displayArray(prices, numelts); cout << "Taxes: "; displayArray(taxes, 5); // array assignment is ILLEGAL // taxes = {2, 2, 3, 8.1}; // total = addTwoArrays(prices, taxes, numelts); addTwoArrays(prices, taxes, total, numelts); cout << " -----------------------------------------" << endl; cout << "Total: "; displayArray(total, numelts); return 0; } // this function accepts an array with n elts. // It displays the n elts to the screen void displayArray(double arr[], int n) { //cout << "You entered " << n << " elements. " << endl; //cout << "Here is the array: " << endl; for (int i=0; i> filename; ifstream inputFile(filename.c_str()); if (!inputFile) { cout << "file did not open."; exit(1); } int n=0; // n stores the number of values read in // read in the values into the array while (n < SIZE && inputFile >> nums[n]) { // Process previous elt (display data) //cout << "You entered: " << idnums[numelts] << ' '; n++; // structured read loop (read in the next piece of data } inputFile.close(); return n; } // this function accepts two arrays as input (arr1 and arr2) // it sums each corresponding element and puts the answer // into the answer array. void addTwoArrays(double arr1[], double arr2[], double answer[], int n) { for (int i=0;i