< previous page page_a61 next page >

Page A61
6. cin >> ch;
   while (cin)
   {
       cout << ch;
       cin >> ch;
   }
10. This solution returns proper results only if the precondition shown in the comments is true. Note that it returns the correct result for base0, which is 1.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int Power( /* in */ int base,
           /* in */ int exponent )

// Precondition:
//     base is assigned && exponent >= 0
// && (base to the exponent power) <= INT_MAX
// Postcondition:
//     Function value == base to the exponent power

{
    int result = 1;     // Holds intermediate powers of base
    int count;          // Loop control variable

    for (count = 1; count <= exponent; count++)
        result = result * base;
    return result;
}
Chapter 9
Case Study Follow-Up
1. Change the body of the function to the following:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
{
    if (isupper(ch))
        upperCount++;
    else if (islower(ch))
        lowerCount++;
    else if (isdigit(ch))
        digitCount++;
    else if (ch ==  )
        blankCount++;
    else if (ch == . || ch == ? || ch == !)
        puncCount++;
    else
        leftOverCount++;
}

 
< previous page page_a61 next page >