C++ examples for Data Type:Array
Displays sales chart, initializes 2-d array
#include <iostream> #include <iomanip> //for setprecision, etc. using namespace std; const int DISTRICTS = 4; //array dimensions const int MONTHS = 3; int main()/*from w w w.j ava2s . co m*/ { int d, m; //initialize array elements double sales[DISTRICTS][MONTHS] = { { 142.07, 34.50, 54.01 }, { 32.00, 1338.32, 1789.88 }, { 938.34, 34.00, 492.30 }, { 1288.29, 232.63, 32.93 } }; cout << "\n\n"; cout << " Month\n"; cout << " 1 2 3"; for(d=0; d<DISTRICTS; d++) { cout <<"\nDistrict " << d+1; for(m=0; m<MONTHS; m++) cout << setw(10) << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2) << sales[d][m]; //access array element } cout << endl; return 0; }