|
|
|
|
|
|
|
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. |
|
|
|
 |
|
|
|
|
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: |
|
|
|
 |
|
|
|
|
{
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++;
} |
|
|
|
|
|