Mixed Up Code Practice

Let’s write the code for the struct definition of Song. The Song structure will have the instance variables string title, string artist, string album, and int year in that order. Put the necessary blocks of code in the correct order.

In main, create a Song object called fly which holds the data for Frank Sinatra’s “Fly Me to the Moon” from his 1964 album “It Might as Well Be Swing”. Put the necessary blocks of code in the correct order.

Let’s write the code for the printSong function. printSong takes a Song as a parameter and prints out the instance variables in the following format: “title” by artist (album, year). Put the necessary blocks of code in the correct order.

Let’s write the code for the struct definition of Unicorn. The Unicorn structure will have the instance variables name, age, hornLength, hairColor, and isSparkly in that order. A Unicorn’s horn length is measured to the nearest tenth of a unit. Put the necessary blocks of code in the correct order.

Let’s write the code for the convertToHumanAge function. convertToHumanAge takes a Unicorn as a parameter and returns the equivalent human age. If a unicorn is sparkly, then its equivalent human age is three times its age in unicorn years plus the length of its horn. If a unicorn is not sparkly, then its equivalent human age is four times its age in unicorn years plus twice the length of its horn. Put the necessary blocks of code in the correct order.

Let’s write the code for the unicornPower function. unicornPower takes a Unicorn as a parameter and sets isSparkly to true and changes the color to rainbow. Put the necessary blocks of code in the correct order.

Let’s write the code for the struct definitions of Address and Employee. The Address structure will have the instance variables houseNumber, state (abbreviation), and postalAddress in that order. The Employee structure will be a nested structure with the instance variables name and Address address in that order. Put the necessary blocks of code in the correct order, with Address defined before Employee.

Let’s write the code for the printAddress function. printAddress takes an Employee as a parameter and should print out the information of the employee in the following format: name (id) lives at houseNumber in state, postalAddress. Put the necessary blocks of code in the correct order.

Sometimes employees will move around and thus we’ll need to update their addresses. Let’s write the code for the updateAddress function. updateAddress takes an Employee and a new Address as parameters and sets the employee’s address to the new address. Put the necessary blocks of code in the correct order.

You have attempted of activities on this page