CS107: C++ Programming Assignment
Question 1
Write a program to read five values into an array and print them out in reverse order (Use two independent for loops).
Question 2
Assume the following declarations are made:
const int little = 6, medium = 10; int k, number[medium];
For each of the following, show what the array looks like after the execution of the code:
a)
for (k = 0; k < medium xss=removed>b)
for (k = 0; k < little xss=removed xss=removed xss=removed>c)
number[0] = 1; k = 1; do { number[k] = 2 * number[k -1]; k++; } while (k < medium>Question 3
Given the statement:
int profit[6] = {150, 300, 500};What is the value of n, when:
a) n = profit[3]
b) n = profit[0]
c) n = profit[6]Question 4
What would be printed by the following program segment:
|
Question 5
An array contains the elements shown below. The first two elements have been sorted using a selection sort. What would be the value of the elements in the array after three more passes of the selection sort algorithm?
1) 7 8 26 44 13 23 98 57
Question 6
We have the following array:
47 3 66 32 56 92
After two passes of a sorting algorithm, the array has been rearranged as shown below:
3 47 66 32 56 92
Which sorting algorithm is being used? Explain your answer.
Question 7
We have the following array:
80 15 21 72 3 33
After two passes of a sorting algorithm, the array has been rearranged as shown below:
15 21 3 33 72 80
Which sorting algorithm is being used? Explain your answer.
Question 8
An array contains the elements shown below. Using the binary search algorithm, trace the steps followed to find 88. At each loop, including the last, show the contents of low, middle, and high.
8 13 17 26 44 56 88 97
Question 9
The program below searches through an unsorted array for any to numbers that match and stops the search if a match is found. Fill in the missing numbers, variable names, or statements in the space provided:
|
Question 10
Based on the following array, what will be the output in each declaration?
char teams[ ] = {'L','a','k','e','r','s','0','N','e','t','s','0'};
a) printf(" %s",teams);
b) printf("%s",teams+7);
c) printf("%s",(teams+3));
d) printf("%s",teams[0]);
e) printf("%c",(teams+0)[0]);
f) printf("%c",(teams+5));
g) printf("%c",(teams-200)[202]);