Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
66 views2 pages

L06-Class Exercises

This document provides 5 examples of C++ code snippets to calculate various values: 1) To calculate interest earned in one year on a bank account with interest rate p and balance, use balance * p. 2) To calculate the side length of a square with area stored in variable area, use sqrt(area). 3) To calculate the volume of a sphere with radius stored in variable radius, use 4/3 * PI * radius^3. 4) To divide 1729 by 10 and get the remainder of 1729 % 10, the results are 172 and 9. 5) To calculate the number of 12-ounce cans needed for an amount of ounces and the leftovers,

Uploaded by

Basra Ajmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views2 pages

L06-Class Exercises

This document provides 5 examples of C++ code snippets to calculate various values: 1) To calculate interest earned in one year on a bank account with interest rate p and balance, use balance * p. 2) To calculate the side length of a square with area stored in variable area, use sqrt(area). 3) To calculate the volume of a sphere with radius stored in variable radius, use 4/3 * PI * radius^3. 4) To divide 1729 by 10 and get the remainder of 1729 % 10, the results are 172 and 9. 5) To calculate the number of 12-ounce cans needed for an amount of ounces and the leftovers,

Uploaded by

Basra Ajmal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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