Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
C++ hw help, i dont understand the question.?
Ok, so i got this emailed hw from ym professor, here is the instruction. But i dont understand what is it asking... what does my professor expect me to do? or what is the program suppose to be about?
Given the following declaration:
int examPrep [12][15];
a. Write a loop to print the first row of the array on one line on cout.
b. Write a loop to print the first column of the array on one line on cout.
c. Write a loop to print the first seven rows of the array, each on a single line.
d. Write a loop to print the entire array backwards and upside down, so that the last line appears first, with last column on the left.
Some help would be apprecated.
What is an Array, btw?
2 Answers
- Anonymous1 decade agoFavorite Answer
If you don't understand simple arrays, this 2-D array is going to stump you, so go back and do some easier array problems to study and get ready for this. Don't worry, you'll get it!
An array holds several values. For example
int someArray[5];
holds 5 values, each of type int. You can even initialize the array right there:
int someArray[5] = { 1, 2, 3, 4, 5 };
That should help you visualize arrays a little. Then, because C/C++ uses "zero based indexing" (we start counting indexes from 0 instead of 1):
someArray[0]; // evaluates to 1
someArray[4]; // evaluates to 5
Looping across an array can allow you to look at each value:
for (int i = 0; i < 5; i++)
callMyFunction( someArray[i] );
From looking at this someArray, you see it is kind of a row of values - we think of it being 5 numbers in a row (i.e. horizontally). A 2-D array, declared as your Professor did,
int examPrep[12][15];
could hold 12 rows of 15 values. Visualized as:
int examPrep[12][15] = {
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} } ;
As you can see, the value 3 is always in the 3rd column in this particular set of values, so because the 3rd column would have an index of 2 (because we stared with 0):
examPrep[x][2]; // always 3, safe for x from 0 to 11
- beedlesLv 45 years ago
Do you remember arithmetic progressions from Algebra I? it is basically what it fairly is. 5 conversions beginning at 7m with an increment of 2m skill that the values to be converted are: 7m, 9m, 11m, 13m, 15m Does that make it clean? The beginning meter fee is 7. The form of conversions is 5. The increment between metric values is 2m.