1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int A[2][2][2] =
//A
//----------
{
//A[0]
//------------
{
//A[0][0]
//-------
//A[0][0][0],A[0][0][1]
{1,2},
//A[0][1]
//------------
//A[0][1][0], A[0][1][1]
{3,4},
},
//A[1]
//----------
{
//A[1][0]
//---------
//A[1][0][0],A[1][0][1]
{5,6},
//A[1][1]
//-----------
//A[1][1][0],A[1][1][1]
{7, 8}
}
};
//Q1: I can't seem to figure out how to have the program
//ignore one set of data and only give me the other set
int choice;
cout << "Enter 1 for 1st set, 2 for second set: ";
cin >> choice;
switch (choice)
{
case 1:
//A[0][i][j],
cout << endl << "Case 1: " << endl << endl;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cout << setw(4) << A[0][i][j];
}
cout << endl;
}
break;
case 2:
//A[1][i][j]
cout << endl << "Case 2: " << endl << endl;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cout << setw(4) << A[1][i][j];
}
cout << endl;
}
break;
default:
cout << "invalid choice" << endl;
}
//Q2: I also don't know how to do addition with values from an array.
//Answer, you should learn arrays from a book if you dont know this.
//access array element with the [] operator.
int sum = A[0][1][1] + A[1][0][0];
cout << endl<< "Sum is "<<sum << endl;
system("pause");
return 0;
}
|