Test 3, CSCI 130, Fall 2011


  1. Casting and Coercion
    1. [3 points] What is type coercion? Give an code example.
    2. [3 points] What is type casting? Give an example.
    3. [4 points] 1 foot = 12 inches. Write a function which will, given the length of an item in inches, find the length in feet. Use the following function prototype.
      float InchesToFeet(int lengthInInches);
      	

  2. If statements
    1. [4 points] Give the syntax for the if-then and if-then-else statements.
    2. [2 points] Show how a code block is used with an if-then statement.
    3. [4 points] Give the flow of control for the if-then-else statement.

  3. While statements
    1. [2 points] Give the syntax for the while statement.
    2. [2 points] Show how a code block is used with a while statement.
    3. [2 points] Why is a code block used with a while statement? (Give example code, explain your example)
    4. [4 points] Give the flow of control for a while statement.

  4. [6 points] State the conditions necessary to successfully construct a loop.

  5. [5 points] Write a routine which takes a student's grade and returns the associated comment, given in the following table. Use the provided function prototype.
    GradePercent ScoreComment
    A 90% to 100% Outstanding Work
    B 80% to 90% Good Work
    C 70% to 80% Average Performance
    D 60% to 70% Poor Work
    F Below 60% Failure
    string GradeComment(char letterGrade);
        

    Over Please

  6. [ 5 points] Write a function which, given a student's percentage score, returns the letter grade. Use the above table and the provided function prototype.
    char GetLetterGrade(float percentScore)
        
  7. [4 points] Write a function which, given a string, will count the number of letters, numbers and other types of characters in the string. Use the provided function prototype.
    void CountCharTypes(string phrase, int & letters, int & digits, int & other);