CPS 6, Quiz Questions, Feb 7-Feb 11, Spring 2000

Two or three of these questions will be used for an in-class quiz at the end of the week. It's possible that the questions may be modified slightly or replace by similar problems.
  1. Write a function that returns the number of vowels in a string so that NumVowels("beauty") evaluates to 4 and NumVowels("strength") evaluates to 1. Assume all characters in the string parameter are lowercase and that a, e, i, o, u, and y are vowels.
    
    
    
    
    
    
    
    
    
    
  2. A month is considered fun if it has more Fridays than Mondays. Write a bool function IsFun that determines if a month specified by 1-12 in a year is fun. The value of IsFun(10,1999) should be true and the value of IsFun(9,1999) is false (the number of mondays is the same as the number of fridays, see the calendars below.)
       October 1999                       September 1999    
     S  M Tu  W Th  F  S		    S  M Tu  W Th  F  S 
                    1  2		             1  2  3  4 
     3  4  5  6  7  8  9		    5  6  7  8  9 10 11 
    10 11 12 13 14 15 16		   12 13 14 15 16 17 18 
    17 18 19 20 21 22 23		   19 20 21 22 23 24 25 
    24 25 26 27 28 29 30		   26 27 28 29 30       
    31
    
    
    
    
    
    
    
    

  3. Write a function that returns both the number of Fridays and the number of Mondays in a month. The header follows:
      void CountMondayFridays(int month, int year, 
                              int & mondayCount, int & fridayCount)
      // pre: 1 <= month <= 12 (1 = january, ... 12 = december)
      // post: mondayCount the # of mondays and fridayCount = # of fridays
    
    
    
    
    
    
    
    
    

  4. Assume the function NumVowels written earlier in the quiz correctly returns the number of vowels in a string. Complete main below to print the string entered by the user that contains the most vowels. If two different strings have the same maximal number of vowels, print the string entered first. int main() { string word; string vowelWord; int maxVowels = 0; while (cin >> word) { } cout << "word with maximal # vowels = " << vowelWord << endl; cout << "# of vowels = " << maxVowels << endl; return 0; }

  5. Write a function CoinFlip that simulates tossing a coin (use a two-sided dice for the coin). The function should return both the number of heads tossed and the number of tails tossed. The number of tosses is passed to the function: void CoinFlip(int numTosses, int & numHeads, int & numTails) // pre: 0 <= numTosses // post: numHeads = # heads tossed, numTails = # tails tossed