One-D_Arrays - CSCI152SampleQuizOneDArrays...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI 152                         Sample Quiz – OneD Arrays                   1.  Given the following declarations:     int list[10] = { 5, 3, 8, 2, 7, 1, 9, 4, 0, 6 };     int n = 4;     Answer these questions, using the original values  for each question:     a)  How many elements are there in list?  _____________________________     b)  What is the subscript  of the largest value in list? _____________________________        c)  Write a statement which will change the value of          the last  element by adding 1 to its current value. _____________________________     d)  What is the value of    list [n]  ?          _____________________________     e)  What is the value of    list [n + 1]  ?      _____________________________     f)  How many  values are output by this loop:          for (n = 1; n < 9; n = n + 2)                cout << list [n];                    _____________________________ 2.  Given these declarations: int array[5];                          int n, k;     Code a loop  which assigns these values to array:        |  0  |  2  |  4  |  6  |_8_|     Hint: look for a relationship between the subscript     and the value stored at that location
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3.  Given these declarations: int array[5];                          int k;      Show the values which are assigned to the array by the execution of the following code:           for (k = 0; k < 5; k++)                        if (k < 2)       |       |      |       |      |      |                array[k] = k + 1;                                   else array[k] = k - 1;
Background image of page 2
4.  a)  Complete this function has parameters of  an array of integers representing bowling scores, and  an integer which is the number of scores in the array.             The function should count and return the number of scores which represent a perfect game            (a score of 300).        int CountPerfect (int scores [], int size)      b)  Call the function from (a) to calculate and output the percentage of perfect games scored  by a bowling league last year.  The variable numScores tells how many values are stored in the league  array.            int numPerfectGames;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/24/2011 for the course CSCI 1302 taught by Professor Harter during the Spring '11 term at Texas A&M University–Commerce.

Page1 / 11

One-D_Arrays - CSCI152SampleQuizOneDArrays...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online