3.17. Activecode Exercises¶
Answer the following Activecode questions to assess what you have learned in this chapter.
Fix the errors in the code below so that it returns the area of
a circle with radius r
.
Use cmath functions to get an accurate value for pi.
Below is one way to fix the program.
C++ doesn’t use the ^
operator for exponents.
We can get the square of r
by multiplying it by itself.
Fix the code below so that it prints “2 elephants”.
Fix the code below so that it prints 12 / 8 = 1.5.
Below is one way to fix the program. It’s crucial that you input your arguments in the correct order so as to avoid a semantic error. Also, it’s important that you understand that when you divide two integers… you will get an integer as a result.
Finish the code below so that it calculates the common log of a
minus the natural log of a
and returns the difference.
You will need to use cmath functions.
Finish the code below so that it prints “First Line”, a border, and “Second Line.” on three separate lines.
Below is one way to complete the program.
Write a function called int_division
that takes two doubles
as parameters and returns the quotient of the integer division
of the first number divided by the second. Be sure to include any necessary headers.
Write a function called gpa_boost
that returns your GPA
rounded up to the nearest whole value.
If your GPA is already at the nearest whole value,
then there is no rounding.
Be sure to include any necessary headers.
Below is one way to complete the program.
I used the ceil <math/ceil> function from the
``cmath` library, but you could have solved this problem
without using any functions from cmath
.
Write a function called volume_prism
that takes three double
side-lengths as parameters, and returns the volume of a the
rectangular prism. Be sure to include any necessary headers.
Write a function called tan_degrees
that returns the
tangent of an angle given as a double
in degrees.
Use 3.14159
for pi.
Be sure to include any necessary headers.
Below is one way to complete the program. You need to make sure to convert your angle to radians before doing any calculations with trigonometric functions.
Write a function called volume_sphere
that takes a double
radius as a parameter and returns the volume of a sphere with
the provided radius.
Use 3.14159
for pi.
Be sure to include any necessary headers.