Question

Look at the following array definition. double sales[8][10]; How many rows does the array have? How many columns does the array have? How many elements does the array have? Write a statement that stores a number in the last column of the last row in the array.

Solution

Verified

Step 1

1 of 4

As previously shown in the previous answers, one may want to define a collection of variables of the same data type. In that situation, declaring a variable for each item separately would not be appropriate\textit{not be appropriate} because of the resulted headache\textbf{headache} from dealing with each one individually\textbf{individually}; therefore, we introduce a collection of variables of the same data type---that is called an array\textbf{\textit{array}}. The array is a collection of variables with the same data type\textit{same data type} that has the same name\textbf{same name} used to reference the whole bunch\textit{whole bunch} of variables.

Nevertheless, one may, further, want to specify an array\textbf{an array} for each element\textit{each element}, within the original array. We, in that situation, model two\textbf{two} types of relationship; assuming representing it as a two-dimensional\textit{two-dimensional} collection, one that exists between rows\textit{rows} of the array, and another one exists among the columns\textit{columns} of that array.

For example\textbf{example}, we may represent the deck of cards as a two-dimensional array where the columns represent suits\textit{suits} and rows represent ranks\textit{ranks}; in that case, the total number of cards would be 13(ranks)4(suits)=5213 (\text{ranks}) * 4 (\text{suits}) = 52

Before viewing the code, we must first specify some details.

  • Array name: the name you would use the access and deal with the array as a whole.

    arr\texttt{arr} in the below code.

  • Array columns' size: the number of columns would exist within your defined array.

    COL_SIZE\texttt{COL\_SIZE} in the below code.

  • Array rows' size: the number of rows would exist within your defined array.

    ROW_SIZE\texttt{ROW\_SIZE} in the below code.

  • Array column's index (subscript): the index used to specify a prticular column within the array.

    col\texttt{col} in the below code.

  • Array row's index (subscript): the index used to specify a prticular row within the array.

    row\texttt{row} in the below code.

There is an important note we should mention here. The range\textbf{range} of any index\textit{index} is [0,(SIZE1)][0,(SIZE-1)] inclusively. The first\textit{first} item has an index 0, and, therefore, the last\textit{last} item has an index SIZE-1.

See the below code.

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionDavid A. Patterson, John L. Hennessy
220 solutions
Starting Out with C++ from Control Structures to Objects 8th Edition by Godfrey Muganda, Judy Walters, Tony Gaddis

Starting Out with C++ from Control Structures to Objects

8th EditionGodfrey Muganda, Judy Walters, Tony Gaddis
1,294 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionRamez Elmasri, Shamkant B. Navathe
687 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions

Related questions