#include <iostream>

using namespace std;

int sumArray(const int array[], int size);

class Square {

    private:
        int side {1};

    public:
        Square() = default;
        Square(int s) : side{s} {};
        int calcArea() {
            return side * side;
        }

};

int main() {

    // Initialize array
    int array[] {4, 8, 15, 16, 23, 42};

    cout << array[1] << endl;

    // Sum up elements of array
    int sum = 0;
    for (int i = 0; i < 6; ++i) {
        sum += array[i];
    }
    cout << sum << endl;

    // Sum up elements using range-based for loop
    int sum2 = 0;
    for (int num: array) {
        sum2 += num;
    }
    cout << sum2 << endl;

    // Using arrays as a function argument
    cout << sumArray(array, 6) << endl;

    // Arrays of objects
    Square squares[] {1, 2, 3, 4, 5};
    for (int i = 0; i < 5; ++i) {
        cout << squares[i].calcArea() << endl;
    }

    return 0;

}

// Function to sum up elements of array using basic for loop
int sumArray(const int array[], int size) {

    int sum = 0;
    
    for (int i = 0; i < size; ++i) {
        sum += array[i];
    }
    
    return sum;

}