You are on page 1of 2

L06 - Class Exercises

1. A bank account earns interest of p percent per year. In C++, how do you compute the
interest earned in one year? Assume variables p and balance of type double have already
been defined.

2. In C++, how do you compute the side length of a square whose area is stored in the
variable area?

3. The volume of a sphere is given by .
If the radius is given by a variable radius of
type double, write a C++ expression for the volume. You may assume that π is defined
by a constant PI.
4. What is the value of 1729 / 10 and 1729 % 10?

5. Suppose a punch recipe calls for a given amount of orange soda, measured in ounces.
int amount = 32;

We can compute the number of 12-ounce cans needed, assuming that the amount does
not evenly divide into 12:

int cans_needed = amount / 12 + 1;

Use the % operator to determine how many ounces will be left over. For example, if 32
ounces are required, we need 3 cans and have 4 ounces left over.

You might also like