3.15. 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 prints the area of a circle with radius 5. 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. We call the function with an argument of 5.

Loading a dynamic question ...
Selecting from: functions_a2, functions_a2_pp

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.

Loading a dynamic question ...
Selecting from: functions_a4, functions_a4_pp

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.

Loading a dynamic question ...
Selecting from: functions_a6, functions_a6_pp

Write a function called gpaBoost that prints your GPA rounded up to the nearest point. If your GPA is already at the nearest point, there is no rounding. Be sure to include any necessary headers.

Below is one way to complete the program. I used the ceil function from the cmath library, but you could have solved this problem without using any functions from cmath.

Loading a dynamic question ...
Selecting from: functions_a8, functions_a8_pp

Write a function called tanD that prints the tangent of an angle given as a double in degrees. Use 3.14 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 sinusoidal functions.

Loading a dynamic question ...
Selecting from: functions_a10, functions_a10_pp

You have attempted of activities on this page