nestedcl.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // nested.cpp -- nested loops and 2-D array
  2. #include <iostream>
  3. #include <string>
  4. #include <array>
  5. const int Cities = 5;
  6. const int Years = 4;
  7. int main()
  8. {
  9. using namespace std;
  10. const string cities[Cities] = // array of pointers
  11. { // to 5 strings
  12. "Gribble City",
  13. "Gribbletown",
  14. "New Gribble",
  15. "San Gribble",
  16. "Gribble Vista"
  17. };
  18. array<array<int,Cities>, Years> maxtemps =
  19. /* int maxtemps[Years][Cities] = // 2-D array */
  20. {
  21. 96, 100, 87, 101, 105, // values for maxtemps[0]
  22. 96, 98, 91, 107, 104, // values for maxtemps[1]
  23. 97, 101, 93, 108, 107, // values for maxtemps[2]
  24. 98, 103, 95, 109, 108 // values for maxtemps[3]
  25. };
  26. cout << "Maximum temperatures for 2008 - 2011\n\n";
  27. for (int city = 0; city < Cities; ++city)
  28. {
  29. cout << cities[city] << ":\t";
  30. for (int year = 0; year < Years; ++year)
  31. cout << maxtemps[year][city] << "\t";
  32. cout << endl;
  33. }
  34. // cin.get();
  35. return 0;
  36. }