Activecode Exercises¶
Answer the following Activecode questions to assess what you have learned in this chapter.
Let’s write the code for the struct definition of Movie
.
The Movie structure will have the instance variables title,
director, and releaseYear in that order.
Below is one way to define the Movie
struct.
Let’s write the code for the printMovie
function.
printMovie should print the information about a movie
in the following format: “title” directed by director (releaseYear).
Below is one way to write the printMovie
function.
Let’s write the code for the movieAge
function.
movieAge should take a Movie and currentYear as a parameter and
return how many years it has been since the releaseYear.
Below is one way to write the movieAge
function.
Let’s write the code for the struct definition of Date
.
The Date structure will have three integer instance variables: day,
month, and year in that order.
Below is one way to define the Date
structure.
Let’s write the code for the printDate
function.
printDate should print the date in the following format:
month/date/year.
Below is one way to write the printDate
function.
Let’s write the code for the nextMonth
function.
nextMonth should change the date to one month later.
For example, 3/4/2020 gets modified to 4/4/2020, and 12/3/2020
gets modified to 1/3/2021.
Below is one way to write the nextMonth function.
Let’s write the code for the struct definition of Length
.
Length should have the instance variables inches, feet, and yard.
Below is one way to defiine the Length
structure.
Let’s write the code for the printLength
function.
printLength should print the date in the following format:
yards yds, feet ft, inches in.
Below is one way to write the printLength
function.
Let’s write the code for the allInches
function.
printLength should modify a Length object to convert all
feet and yards to inches. For example, a Length with 1 yard, 2 feet, and 3
inches is converted into a Length with 0 yards, 0 feet, and 63 inches.
Below is one way to write the allInches
function.
Let’s write the code for the addLengths
function.
addLengths should take three Lengths as parameters.
It should then add the first two Lengths and store the result
in the third Length. If there is over 12 inches or over 3 feet,
convert it to the proper amound of feet and yards (13 inches becomes 1 foot and 1 inch).
Below is one way to write the addLengths
function.