Mixed-Up Code Exercises

Answer the following Mixed-Up Code questions to assess what you have learned in this chapter.

Construct a function that correctly prints the integer conversion of the passed double.

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 “… … … …”

Construct a function that 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.

Construct a function that prints the sin of an angle given in degrees. Use 3.14 for pi.

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

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.

The chickens from the previous chapter are infuriated. Construct a function 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.

Construct a function 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.

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 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).

Your final grade is determined by a midterm component (each midterm is worth 20% of the grade) and a final component. 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 that determines a student’s final grade percentage according to this grading scheme and prints the result.

You have attempted of activities on this page