Chapter 7: Problem 5
include
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
Chapter 7: Problem 5
include
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for freeState whether the following are true or false. If the answer is false, explain why. a. An array can store many different types of values. b. An array subscript should normally be of data type float. c. If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list. d. It is an error if an initializer list contains more initializers than there are elements in the array. e. An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution.
Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [ Note: Each die can show an integer value from 1 to \(6,\) so the sum of the two values will vary from 2 to \(12,\) with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] Figure 7.32 shows the 36 possible combinations of the two dice. Your program should roll the two dice 36,000 times. Use a onedimensional array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable (i.e., there are six ways to roll a \(7,\) so approximately one-sixth of all the rolls should be 7 ).
(Bubble Sort) In the bubble sort algorithm, smaller values gradually "bubble" their way upward to the top of the array like air bubbles rising in water, while the larger values sink to the bottom. The bubble sort makes several passes through the array. On each pass, successive pairs of elements are compared. If a pair is in increasing order (or the values are identical), we leave the values as they are. If a pair is in decreasing order, their values are swapped in the array. Write a program that sorts an array of 10 integers using bubble sort.
Determine whether each of the following is true or false. If false, explain why. a. To refer to a particular location or element within an array, we specify the name of the array and the value of the particular element. b. An array declaration reserves space for the array. c. To indicate that 100 locations should be reserved for integer array p, the programmer writes the declaration p[ 100 ]; d. A for statement must be used to initialize the elements of a 15- element array to zero. e. Nested for statements must be used to total the elements of a two- dimensional array.
(Palindromes) A palindrome is a string that is spelled the same way forward and backward. Some examples of palindromes are "radar, " "able was i ere i saw elba" and (if blanks are ignored) "a man a plan a canal panama." Write a recursive function testpalindrome that returns true if the string stored in the array is a palindrome, and false otherwise. The function should ignore spaces and punctuation in the string.
What do you think about this solution?
We value your feedback to improve our textbook solutions.