2.16. Activecode Exercises¶
Answer the following Activecode questions to assess what you have learned in this chapter.
Fix the code below so that it compiles and runs without errors. Hint: you might need to change the names of some variables.
Below is one way to fix the program. true
and false
are keywords, so they cannot be used as variable names.
Finish the code below so that it prints “I drive a 2014 Buick Regal”.
This code does not need to include a main. It is already provided as part of the test.
Fix the code below so that it prints “Cady scored 90% on the exam.”
Below is one way to fix the program. We want to use doubles so that our result isn’t truncated to 0 through integer division.
Finish the code below so that it shows the correct volume of a sphere. Hint: watch out for integer division.
This code does not need to include a main. It is already provided as part of the test.
Fix the code below so that assigns a
its correct value of 'a'
.
Hint: use character operations!
Below is one way to complete the program.
There are many creative ways that you could use the
order of operations to come up with a complex expression that
will bring you to 'a'
, here is one way.
Finish this program so that it assigns “apples” to the variable oranges, and “oranges” to the variable apples, then swaps their values. Be sure to inclue any necessary headers.
Avoid ‘hardcoding’ your solution.
Write code that prints “Live”, “Laugh”, and “Love” on 3 consecutive lines. Be sure to inclue any necessary headers.
Below is one way to implement the solution.
Write code that calculates how much you you will spend after
tipping 20% on your $36.25 dinner.
Store the tip in a variable tip
.
Save the final result of this calculation in plus_tip
.
This code does not need to include a main. It is already provided as part of the test.
You have about three hours and fifteen minutes of homework to do today.
Rather than starting it right away, you choose to procrastinate
by calculating how many seconds you’ll be spending on your work.
Convert the time to seconds and store the result in seconds
.
This code does not need to include a main. It is already provided as part of the test.
Below is one way to implement the solution.
Write code that calculates and prints the average of a and b if a = 3.14, and b = 1.59. You may only use one line of code. Be sure to inclue any necessary headers.