Define the following arrays: a) empNum, a 100 -element array of ints b) pay Rate, a 25-element array of doubles c) miles, a 14-element array of longs d) stateCapital, a 50-element array of string objects . e) lightYears, a 1,000-element array of doubles
DCS1101: Fundamental of Programming Tutorial 8 – Array
1. Define the following arrays:
a) empNum, a 100 -element array of ints
b) pay Rate, a 25-element array of doubles
c) miles, a 14-element array of longs
d) stateCapital, a 50-element array of string objects .
e) lightYears, a 1,000-element array of doubles
2. Assume a program includes the following two statements. They both use square brackets, but they mean different things. int score[15] ; score[6] = 45 ;
a) Which number is the size declarator ?
b) Which number is a subscript?
3. What is the output of the following code? int values[5], count; for (count= 0; count< 5; count++) values[count ] =count+ 1; for (count= O; count< 5; count++) cout << values[count] << endl;
4. Complete the following program skeleton so it will have a 10-element array of int values called fish. When completed, the program should ask how many fish were caught by fishermen 1 through 10, and store this information in the array. Then it should display the data. #include using namespace std; int main () { const int NUMMEN = 10 ; II Define an array named fish that can hold 10 int values. II You must finish this program so it works as II described above. return O; }
5. Define the following arrays :
a) ages, a 10-element array of ints initialized with the values 5, 7, 9, 14, 15, 17, 18, 19, 21, and 23
b) temps , a 7-element array of doubles initialized with the values 14.7, 16.3,18.43, 21.09, 17.9, 18.76, and 26 .7
c) alpha, an 8-element array of chars initialized with the values 'J', 'B', 'L','A' ,"*" ,'$ ', 'H', and 'M'
6. Given the following array definition: int values [ ] = { 2 , 6, 10, 14} ; what do each of the following display?
a) cout << values[2] ;
b) cout << ++values [0] ;
c) cout << values[1]++;
d) x = 2 ; cout << values[++x ] ;
7. Define a two -dimensional array of ints named grades . It should have 30 rows and 10 columns.
8. How many elements are in the following array? double sales[6 ][ 4] ;
Trending now
This is a popular solution!
Step by step
Solved in 2 steps