Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

(Fill in the Blanks) Answer each of the following: a) Lists and tables of values can be stored in ___ or ___. b) The elements of an array are related by the fact that they have the same ___ and __. c) The number used to refer to a particular element of an array is called its __. d) \(A(n)\) __ should be used to declare the size of an array, because it makes the program more scalable. e) The process of placing the elements of an array in order is called __ the array.vv f) The process of determining if an array contains a particular key value is called __ the array. g) An array that uses two subscripts is referred to as a(n) __ array.

Short Answer

Expert verified
a) arrays or lists b) data type and index c) index d) variable or constant identifier e) sorting f) searching g) two-dimensional or 2D

Step by step solution

01

Fill in the blank a

Review the context to understand that lists and tables of values can be stored in data structures. Based on common data structures used for storing such elements, the words to fill in the blanks are 'arrays' or 'lists'.
02

Fill in the blank b

Consider the properties that array elements share. All elements in an array have the same 'data type' and are accessed by their 'index'.
03

Fill in the blank c

Understand what is used to access a specific element in an array. The term that is used is the 'index' or 'subscript' of the element.
04

Fill in the blank d

Consider best practice in programming when declaring the size of an array. Using a 'variable' or 'constant identifier' allows for scalability, thus it is encouraged to use those to declare array sizes.
05

Fill in the blank e

Identify the term that describes organizing the elements of an array. The process of placing the elements in order is known as 'sorting' the array.
06

Fill in the blank f

Determine the term for finding a particular value within an array. The search for a specific value is referred to as 'searching' the array.
07

Fill in the blank g

Recognize the terminology for an array that requires two indices to access an element. Such an array is known as a 'two-dimensional' or '2D' array.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

Arrays in C++
In C++, an array is a series of elements that can store a fixed-size sequential collection of items of the same type. They provide a convenient way to group related data, such as a list of integers or a table of characters. When declaring an array, you specify its type and size, for example, int myArray[10]; would create an array that can hold 10 integers. It's important to understand that in C++, array indexing starts from zero, meaning the first element of the array is myArray[0], the second is myArray[1], and so forth.

Arrays are a foundational data structure in C++ and are used in various ways, from simple data storage to acting as building blocks for more complex data structures. They are particularly useful when you need to perform operations involving multiple similar elements, or when accessing individual elements by their index is necessary. Moreover, using constants or variables for declaring array size, as seen in the exercise, is a good practice to enhance code flexibility and readability.
Indexing in Arrays
Indexing is the way in which elements within an array are accessed. Each element in an array has a specific, zero-based index that uniquely identifies its position. For instance, to access the third element in the array myArray, one would use myArray[2]. This is because arrays in C++ use zero-based indexing, meaning the count starts at zero rather than one.

It's crucial to be careful with indexing to avoid 'out-of-bounds' errors, which occur when trying to access an index that doesn't exist within the array. Always ensure that the index you're using is within the range from 0 to the size of the array minus one. Indexing enables efficient retrieval and manipulation of array elements, and it's a fundamental concept to grasp for proper array usage.
Sorting Arrays
Sorting is the process of arranging the elements in an array in a particular order, such as ascending or descending. C++ does not have a built-in sort function for arrays, but there are several algorithms that you can implement, such as bubble sort, selection sort, and insertion sort, for simple arrays.

For more advanced sorting needs, the C++ Standard Library offers the sort() function found in the header which can sort elements in an array or in a container provided by the C++ Standard Library. Sorting is an essential operation for organizing data and can significantly improve the efficiency of search operations and data comparison tasks.
Searching Arrays
Searching through an array involves looking for a specific element, often referred to as the 'key'. Linear search and binary search are two fundamental algorithms for this task. A linear search scans each element of the array until it finds the key or reaches the end of the array. It is straightforward but can be slow for large arrays since it may have to go through all elements.

A binary search, on the other hand, is much faster but requires the array to be sorted. It repeatedly divides the search interval in half, comparing the mid-point with the key. If the mid-point is equal to the key, the search is successful. If the key is less than the mid-point, it updates the interval to the lower half; otherwise, to the upper half. Performing searches efficiently is crucial for many applications, such as databases and user queries.
Two-Dimensional Arrays
Two-dimensional arrays, also known as 2D arrays, are essentially arrays of arrays. They are used to store data in a grid-like structure, consisting of rows and columns, making them ideal for storing information like matrices or tables. To declare a 2D array in C++, you specify the type, followed by two sets of square brackets indicating the number of rows and columns, respectively, like int my2DArray[5][4];.

Accessing elements in a 2D array requires two indices: one for the row and one for the column. For example, my2DArray[2][3] accesses the element in the third row and fourth column. 2D arrays further extend the utility of basic arrays and are particularly important in areas dealing with multi-dimensional data, such as graphics, game development, and scientific computing.
Data Structures in C++
Data structures are a way of organizing and storing data in a computer so that it can be accessed and modified efficiently. In C++, aside from fundamental data structures like arrays, there are several more complex data structures available in the Standard Template Library (STL). These include
  • vector: a dynamic array that can change size
  • list: a doubly-linked list
  • map: a sorted associative container that contains key-value pairs
  • set: a container that stores unique elements in sorted order
Understanding these data structures and knowing when to use each is critical for effective problem-solving in C++. The STL also provides algorithms that can perform operations on these structures, such as sorting, searching, and more complex manipulations. Proper utilization of data structures is key to creating efficient and scalable C++ programs.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

( Sales Summary ) Use a two-dimensional array to solve the following problem. A company has four salespeople ( 1 to 4 ) who sell five different products ( 1 to 5 ). Once a day, each salesperson passes in a slip for cach different type of product sold. Each slip contains the following: a) The salesperson number b) The product number c) The total dollar value of that product sold that day Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month's sales (one salesperson's data at a time) and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, print the results in tabular format with cach of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns.

(Fill in the Blanks) Fill in the blanks in each of the following: a) The names of the four elements of array p (int p[4];) are ___, ___ , ___ and ___. b) Naming an array, stating its type and specifying the number of elements in the array is called __ the array. c) By convention, the first subscript in a two-dimensional array identifies an element's ___ and the second subscript identifies an element's ___. d) An m-by-n array contains __ rows, __ columns and ___ elements. c) The name of the element in row 3 and column 5 of array \(d\) is __.

(Double Array Initialization) Label the elements of a 3 -by- 5 two-dimensional array sales to indicate the order in which they're set to zero by the following program segment: for ( row = 0; row < 3; ++row ) for ( column = 0; column < 5; ++column ) sales[ row ][ column ] = 0;

(Single Array Questions) Write single statements that perform the following one-dimensional array operations: a) Initialize the 10 elements of integer array counts to zero. b) Add 1 to each of the 15 elements of integer array bonus. c) Read 12 values for double array month 7 yTemperatures from the keyboard. d) Print the 5 values of integer array bestscores in column format.

(Bubble Sort Enbancements) The bubble sort described in Exercise 7.11 is inefficient for large arrays. Make the following simple modifications to improve the performance of the bubble sort: a) After the first pass, the largest number is guaranteed to be in the highest-numbered element of the array; after the second pass, the two highest numbers are "in place," and so on. Instead of making nine comparisons on every pass, modify the bubble sort to make eight comparisons on the second pass, seven on the third pass, and so on. b) The data in the array may already be in the proper order or near-proper order, so why make nine passes if fewer will suffice? Modify the sort to check at the end of each pass if any swaps have been made. If none have been made, then the data must already be in the proper order, so the program should terminate. If swaps have been made, then at least one more pass is needed.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free