Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
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.