/*--- CS 111 - Week 14 Lecture 1 - 2024-12-03 by: Sharon Tuttle last modified: 2024-12-03 ---*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> using namespace std; /*=== signature: sum_array: double[] int -> double purpose: expects an array of numbers and its size, and returns the sum of all of the elements in that array. tests: if I have: double my_list[5] = {10, 20.1, 3, 4, 100}; sum_array(my_list, 5) == 137.1 if I have: double my_quants[4] = {20, 66, 34, -5}; sum_array(my_quants, 4) == 115 ===*/ double sum_array(double nums[], int size) { int i = 0; // i for index double sum_so_far = 0; while (i < size) { sum_so_far = sum_so_far + nums[i]; i = i + 1; } return sum_so_far; } /*=== signature: get_smallest: double[] int -> double purpose: expects an array of numbers and its size, and returns the value of the smallest element(s) in that array tests if I have: double my_list[5] = {10, 20.1, 3, 4, 100}; get_smallest(my_list, 5) == 3 if I have: double my_quants[4] = {20, 66, 34, -5}; get_smallest(my_quants, 4) == -5 ===*/ double get_smallest(double numbers[], int size) { // in progress, to be finished Thursday/Week 14 Lecture 2! return 0.0; } /*--- test the functions above ---*/ int main() { cout << boolalpha; cout << "*** Testing: sum_array ***" << endl; double my_list[5] = {10, 20.1, 3, 4, 100}; cout << (sum_array(my_list, 5) == 137.1) << endl; double my_quants[4] = {20, 66, 34, -5}; cout << (sum_array(my_quants, 4) == 115) << endl; cout << endl; cout << "just for fun: the average of the values in " << "my_quants: " << (sum_array(my_quants, 4) / 4) << endl; return EXIT_SUCCESS; }