Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is an array? Give examples of when to use a 1 dimensional array. I need a c

ID: 3659604 • Letter: W

Question

What is an array? Give examples of when to use a 1 dimensional array. I need a couple short examples.

Explanation / Answer

n this Web page we will look at the simplest kinds of arrays. Thus we will only look at 1-dimensional arrays and won't do any complicated processing with them. For more advanced information on arrays, look at the intermediate section on Arrays in these Web pages. A 1-dimensional array is used to hold a sequence of items all of the same type. An index number is used to specify each storage location in the array. In C++ indexing begins with 0. For an array named A, the first storage location is A[0], the second location is A[1], etc. An array of 8 integers would look like this: Let's assume that the name of this array is A. We could place the 20 into array location 0 by using the following assignment statement: A[0] = 20; We could read a number into an array location, also. For example, to read in a number into array location 1 we might use something like this: cout > A[1]; Since we often want to place numbers into all of the array locations, we are likely to write a loop to handle things. In many cases we know the number of items to be processed, so that a FOR loop is typical. Here is an example of a FOR loop that reads numbers into all 8 locations of our array A. This is followed by another FOR loop that writes out all of the data in array A. int k; for (k = 0; k < 8; k++) { cout > A[k]; } for (k = 0; k < 8; k++) cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote