| 5 | #include <format> |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | try |
| 10 | { |
| 11 | const size_t numValues {20}; |
| 12 | Array<double> values {numValues}; |
| 13 | |
| 14 | for (unsigned i {}; i < numValues; ++i) |
| 15 | values[i] = i + 1; |
| 16 | |
| 17 | std::cout << "Sums of pairs of elements:"; |
| 18 | size_t lines {}; |
| 19 | for (size_t i {numValues - 1}; i >= 0; --i) |
| 20 | { |
| 21 | std::cout << (lines++ % 5 == 0 ? "\n" : "") |
| 22 | << std::format("{:5g}", values[i] + values[i-1]); |
| 23 | } |
| 24 | } |
| 25 | catch (const std::out_of_range& ex) |
| 26 | { |
| 27 | std::cerr << "\nout_of_range exception object caught! " << ex.what() << std::endl; |
| 28 | } |
| 29 | |
| 30 | try |
| 31 | { |
| 32 | const size_t numBoxes {5}; |
| 33 | Array<Box> boxes {numBoxes}; |
| 34 | for (size_t i {} ; i <= numBoxes ; ++i) |
| 35 | std::cout << "Box volume is " << boxes[i].volume() << std::endl; |
| 36 | } |
| 37 | catch (const std::out_of_range& ex) |
| 38 | { |
| 39 | std::cerr << "\nout_of_range exception object caught! " << ex.what() << std::endl; |
| 40 | } |
| 41 | } |