1. Consider the following array definition:
int values[5] = {4,7,6,8,2};
What does each of the following statements display?
cout << values[4] << endl;
cout<< (values[2] + values[3])<<endl;
cout << ++values[1] << endl;
2. marks is an integer array with 20 elements. Write a for loop that prints each element of the array.
3. The arrays numberArray1 and numberArray2 have 100 elements. Write code that copies the values in numberArray1 to numberArray2.
4. In a program you need to store the identification numbers of 10 employees (as ints) and their weekly gross pay (as doubles).
A) Define two arrays that may be used in parallel to store the 10 employee identification numbers and gross pay amounts.
B) Write a loop that uses these arrays to print each employee’s identification number and weekly gross pay.
C) Write a loop that accumulates the weekly gross pay for all employees and outputs that amount.
5. Consider the following array:
int a[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
What is the value of total after the following loops complete?
a. int total = 0;
for (int i = 0; i < 10; i++) { total = total + a[i];}
b. int total = 0;
for (int i = 0; i < 10; i=i+2) { total = total + a[i];}
c. int total = 0;
for (int i = 1; i < 10; i=i+2) { total = total + a[i];}
d. int total = 0;
for (int i = 2; i <= 10; i++) { total = total + a[i];}
e. int total = 0;
for (int i = 0; i < 10; i=2 * i) { total = total + a[i];}
f. int total = 0;
for (int i = 9; i >= 0; i--) { total = total + a[i];}
g. int total = 0;
for (int i = 9; i >= 0; i=i - 2) { total = total + a[i];}
h. int total = 0;
for (int i = 0; i < 10; i++) { total = a[i] – total;}
6. Consider the following array:
int a[ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
What are the contents of the array after the following loops complete?
a. for (int i = 1; i < 10; i++) { a[i] = a[i– 1]; }
b. for (int i = 9; i > 0; i--) { a[i] = a[i – 1]; }
c. for (int i = 0; i < 9; i++) { a[i] = a[i + 1]; }
d. for (int i = 8; i >= 0; i--) { a[i] = a[i + 1]; }
e. for (int i = 1; i < 10; i++) { a[i] = a[i ] + a[i– 1]; }
f. for (int i = 1; i < 10; i = i + 2) { a[i] = 0;}
g. for (int i = 0; i < 5; i++) { a[i + 5] = a[i]; }
h. for (int i = 1; i < 5; i++) { a[i] = a[9 - i]; }
7. True or False?
a. All elements of a vector are of the same type.
b. Vector subscripts must be integers.
c. Vectors cannot contain strings as elements.
d. Vectors cannot use strings as subscripts.
e. Two-dimensional arrays always have the same number of rows and columns.
f. Elements of different columns in a two-dimensional array can have different types.
g. All vector parameters are reference parameters.
h. A function cannot return a two-dimensional array.
i. A function cannot change the dimensions of a two-dimensional array that is passed as a parameter.
j. A function cannot change the length of a vector that is passed by reference.
Do the following Programs. Remember to show a sample output
8. Largest/Smallest Array Values
Write a program that lets the user enter 10 values into an array. The program should then display the largest and smallest values stored in the array.
9. Do question 8 (above) again this time using 5 functions.
void getValues(int [], int);
void displayValues(const int[], int);
int largest(const int[],int);
int smallest(const int[],int);
void displayLargestSmallest(int,int);
Since the OP has no questions, I assume its to share fascinating excercises with others, so we can silently test, if we understood some basics of C and C++.