Please answer all C++ VERY QUICK related question (10-23) for positive rate. A d
ID: 3586153 • Letter: P
Question
Please answer all C++ VERY QUICK related question (10-23) for positive rate.
A data structure is a collection of related datums that can be operated upon. An array is a simple data structure—all datums in an array (that is, the elements of the array) have the same data type (homogeneity) and each datum is randomly-accessible accomplished by using a unique index in addition to the array name. In most programming languages the index range for an array that contains n elements is the set of integers [ 0,n-1 ].
Defining an array always requires the programmer to specify the name of the array and the data type of the elements. Most implementations of the array concept also require the programmer to specify the number of elements. For example,
int A[10]; // 1-dimensional array (a vector)
double matrix[20][10]; // 2-dimensional array (a table)
Some implementations of the array concept use contiguous memory locations to store the array elements. Contiguous allocation of array elements allows the random-accessing operation to be very efficient (that is, the algorithm for random access of array elements is (1)).
The data defined below are used in the following Questions concerned with the built-in pointer-based implementation of the array concept.
int a1[10];
int *a2 = new int [10];
short int b[10][25];
char c[10][80];
int A[3][3] = { {1,2,3},{3,4,5},{6,3,7} };
int *Ap = A;
double d[1024];
char* cp1,cp2;
10. What are the essential differences between the arrays a1 and a2? Hint Use the words statically-allocated, dynamically-allocated, location, and duration (lifetime) in your answer.
11. T or F? a1[i] == *(a1 + i), "i Î { 0,1,2,...,10 }
12. How many elements does the array b contain? ______
13. How many bytes does the array b contain? ______
14. Assume c is used to store NUL-terminated strings and ((int) strlen(c[i]) == 5),
"i Î { 0,1,2,...,9 }. T or F? (&c[i][5] < &c[i+1][0]) "i Î { 0,1,2,...,8 }
15. What’s wrong with the following statements? Hint The problems are not with the syntax used because both statements “compile”.
cin >> cp1;
cin >> *cp1
16. Complete the void-returning function SetToZero() that zeroes all n elements of the array that x points-to. You may not use the array element selector operator []; therefore, you must use pointer-based arithmetic and the dereferencing operator '*'.
void SetToZero(int *x,int n)
{
}
17. (Continuing 16) T or F? In the function header for SetToZero () both x and n are scalar[1] variables.
18. What is A[2][2]? ______ When A (or equivalently &A[0][0]) is FABC000016, what is &A[2][2]? ______
19. When d is not sorted, what is the maximum number of probes needed to complete a failed linear search of d? ______
20. When d is sorted, what is the maximum number of probes needed to complete a failed binary search of d? ______
21. T or F? Both cp1 and cp2 are pointertochar variables.
22. T or F? (Ap == A) && (A == &A[0])
23. Assume int *Ap = &A[1] T or F? (++Ap == &A[2])
[1] A scalar is an atomic quantity that can hold only one value at a time. From https://en.wikipedia.org/wiki/Scalar on September 21, 2017.
Explanation / Answer
Answers are as follows:
10.
The difference between the two arrays are as follows:
a. Array a1 is statically allocated i.e the size of this array is fixed and it can not be changed in future while array a2 is dynamically allocated i.e we can add new elements to the array even after the size is exceeded by adding more size to the array
b. In Array a1 the memory is allocated contiguously i.e the elements ot item stored in array will be stored in the memory as a single block without any other process or information in between while in array a2 the elements are stored not continuously and on discrete locations and they need not be stored one after the another.
c. Lifetime of array a1 is till the function or the block in which it is created, exists, once that block or function is finished but array 2 will exist as long as the complete program is not over.
11.
Yes its true that a1[i] == *(a1 + i) because here we are using pointers to represent array and this kind of notation is legal or working in th C or C++ grammar.
12.
Since array b is a two dimesnsional array it can be considered as a 2-D box with 10 row and 25 columns
Thus number of elements in the array b = 10 * 25 =250
13.
Size of array b= (Size of one element in array b)* Number of elements
= 2 bytes * 250 { size of short int element= 2bytes
=500 bytes.
Due to Chegg Policy i can answer only first four subparts.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.