Advertisement
reellearning

Intro to Arrays in C++ (Arrays Container Class)

Jun 27th, 2012
1,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. /*
  2.  * arrays.cpp
  3.  *
  4.  *  Created on: Jun 25, 2012
  5.  *      Author: Derek
  6.  *
  7.  *  Example to introduce the array container class
  8.  *  Iterators will be covered in a later example.
  9.  */
  10.  
  11.  
  12. #include <iostream>
  13. #include <array>
  14. using namespace std;
  15.  
  16. int main()
  17. {
  18.     array <double, 5> rainfall;
  19.  
  20.     rainfall[0] = 2.3;
  21.     rainfall[1] = 0.3;
  22.     rainfall[2] = 0.0;
  23.     rainfall[3] = 4.1;
  24.     rainfall[4] = 0.5;
  25.  
  26.     rainfall.at(5) = 7.2;
  27.  
  28.  
  29.     // Should use iterator to traverse array container
  30.     for(size_t i = 0; i < rainfall.size(); i++)
  31.     {
  32.         cout << rainfall[i] << endl;
  33.     }
  34.  
  35.     for(size_t i = 0; i < rainfall.size(); i++)
  36.     {
  37.         cout << "Enter a rainfall amount: " << endl;
  38.         cin >> rainfall[i];
  39.     }
  40.  
  41.     for(size_t i = 0; i < rainfall.size(); i++)
  42.     {
  43.         cout << rainfall[i] << endl;
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement