12345678910111213141516171819202122232425262728293031323334353637383940 |
- //arrobj.cpp -- functions with array objects
- #include <iostream>
- #include <array>
- #include <string>
- const int Seasons = 4;
- const std::array<std::string, Seasons> Snames =
- {"Spring", "Summer", "Fall", "Winter"};
- void fill(std::array<double, Seasons> * pa);
- void show(std::array<double, Seasons> da);
- int main()
- {
- std::array<double, 4> expenses;
- fill(&expenses);
- show(expenses);
- // std::cin.get();
- // std::cin.get();
- return 0;
- }
- void fill(std::array<double, Seasons> * pa)
- {
- for (int i = 0; i < Seasons; i++)
- {
- std::cout << "Enter " << Snames[i] << " expenses: ";
- std::cin >> (*pa)[i];
- }
- }
- void show(std::array<double, Seasons> da)
- {
- double total = 0.0;
- std::cout << "\nEXPENSES\n";
- for (int i = 0; i < Seasons; i++)
- {
- std::cout << Snames[i] << ": $" << da[i] << '\n';
- total += da[i];
- }
- std::cout << "Total: $" << total << '\n';
- }
|