# Activecode Exercises¶

Answer the following **Activecode** questions to
assess what you have learned in this chapter.

Construct a function `printInteger`

that correctly prints the integer conversion of the passed double.

Below is one way to write the `printInteger`

function.

Construct a function called `newLine`

that takes no arguments and prints a blank line. Then construct another function called `divider`

that prints two blank lines separated by a line of “… … … …”

Below is one way to write the two functions, `newLine`

and `divider`

.

Construct a function, `volumeCone`

, that takes as inputs the radius then the height and correctly calculates the volume of a cone with as much precision as possible and prints the value to the terminal. Use 3.14 for pi.

Below is one way to write the `volumeCone`

function.

Construct a function, `sineDegrees`

, that prints the sin of an angle given in degrees. Use 3.14 for pi.

Below is one way to write the `sineDegrees`

function.

Construct a function, `finalPrice`

, that prints the price (with 8% sales tax) of an item with after using a 30% off coupon.

Below is one way to write the `finalPrice`

function.

Suppose you have already defined a function called `sumOfSquares`

which returns the sum of the squares of two numbers and `root`

which returns the square root of a number. Construct a function that calculates the hypotenuse of the right triangle and prints the three sidelengths.

Below is one way to write the `sumOfSquares`

and `root`

functions.

The chickens from the previous chapter are infuriated. Construct a function, `eatMore`

, that prints “Eat” on the first line, “More” on the second line, and the name of the passed animal on the fourth line, followed by an exclamation point.

Below is one way to write the `eatMore`

function.

Construct a function, `printAmount`

, that takes a dollar amount and cent amount and prints the total amount of money that you have. Hint: the mod operator ‘%’ returns the remainder of a division.

Below is onw way to write the `printAmount`

function.

In Michigan, the probability that it snows on any given day in the winter is about 14%. The probability of having a snow day on any given day in the winter is about 4%. The probability that is snows and you have a snow day is 8%.
Construct and call a function, `conditionalProb`

, that calculates the probability of a having a snow day, given the fact that it will snow tonight.
For reference, the formula for conditional probability is: P(A|B) = P(B and A) / P(B).

Below is one way to write and call the `conditionalProb`

function.

Your final grade is determined by a midterm component (each midterm is worth 20% of the grade) and a final component that is worth 60% of the grade. In order to avoid any discrepancies with students who’s grades are on the fence, your teacher follows this strict grading scale:
[0%,60%) = F, [60%, 70%) = D, [70%, 80%) = C, [80%, 90%) = B and [90%, 100%] = A. He does not round until the very end.
Construct a function, `finalGrade`

, that determines a student’s final grade percentage according to this grading scheme and prints the result.

Below is one way to construct the `finalGrade`

function.