Computer Science 2610

Spring 2000

Quiz 4

 

 

  1. Write a function called numvowels that takes a null-terminated string as a parameter and returns the number of vowels in the string.  Assume that function isvowel is available, where isvowel(c) is true when character c is a vowel.  For example, numvowels(“rabbit”) = 2.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. Suppose that array an array called mouse has been created, and is declared as follows.

 

         char mouse[30];

 

      Suppose that a null-terminated string has been put in array mouse.  Using the function numvowels, you would like to set integer variable v to the number of vowels in the string that is stored in array mouse.  Which of the following statements will do the job?

 

(a)   v = numvowels(“mouse”);

(b)  v = numvowels(mouse[]);

(c)   v = numvowels(mouse[30]);

(d)  v = numvowels(mouse);

 


  1. To within a constant factor (that is, in terms of proportionality) how long does it take to do a binary search on an array of size n?

(a)   log2(n)

(b)  n

(c)   n log2(n)

(d)  n2

 

  1. With an error of no more than 1, what is log(256)?

(a)   4

(b)  6

(c)   8

(d)  10

 

  1. To within a constant factor, how long does the exchange sort algorithm take to sort an array of n items?

(a)   log(n)

(b)  n

(c)   n log(n)

(d)  n

 

 

  1. Which of the following is a C++ standard library function that finds the length of a null-terminated string?

(a)   lenstr

(b)  strlen

(c)   length

(d)  stringlen

 

  1. Suppose that T is a two-dimensional array of integers, defined by

 

int T[10][20];

 

You would like to select the member of T that is in the upper left-hand corner.  (That is, it is in the first column and the first row of the array.)

Which of the following expressions returns that value?

 

(a)   T[0,0]

(b)  T[0][0]

(c)   T[1,1]

(d)  T[1][1]