Mixed Up Code Practice

Let’s write the struct definition for Song. Song should have instance variables title, artist, and numLikes. Put the necessary blocks of code in the correct order.

Let’s make an album! Write the struct definition for Album, which should have instance variables name, year and a vector of Songs. Put the necessary blocks of code in the correct order.

Two Songs are equal if the title and artist of the Songs are equal. Write the function songEqual, which takes two Songs as parameters and returns true if they are equal. Put the necessary blocks of code in the correct order.

What if we’d like to search an album for our favorite song? Write the Album member function searchAlbum which takes a Song as a parameter and returns the location of the Song in the album. If the song isn’t found, return -1. Use the songEqual function we defined earlier! Put the necessary blocks of code in the correct order.

What’s the most popular Song within an Album? Let’s write the Album member function mostLikedSong, which prints out the information of the most liked Song in the format “The most liked song is title by artist with numLikes likes.” Put the necessary blocks of code in the correct order.

Let’s write the struct definition for Product. Product should have instance variables name and price. Put the necessary blocks of code in the correct order.

Let’s make a shopping list! Write the struct definition for List, which should have instance variables type and a vector of Products. Put the necessary blocks of code in the correct order.

Two Products are equal if the name and price of the Products are equal. Write the function productEqual, which takes two Products as parameters and returns true if they are equal. What if we want to check to see if we have bananas in our shopping list? Write the List member function searchList, which takes a Product as a parameter and returns the location of the Product in the List. Return -1 if it’s not in the List. Put the necessary blocks of code in the correct order.

Time to checkout! Write the List member function totalPrice which calculates and returns the total price of all the Products. Put the necessary blocks of code in the correct order.

Oops! We made a mistake and grabbed pineapple pizza. What if we want to remove an Product from our List? Write the List member function removeProduct, which takes an index as a parameter and removes it. Then it fills the gap with the last product in the List. Put the necessary blocks of code in the correct order.

You have attempted of activities on this page