Lab 9

Solution has been posted!

 Lab 9: Amazon music service - Using Dynamic Arrays

 

 In this lab, you will learn to use "Dynamic arrays"

 

 The problem

 ============

 

 Amazon music service was launched recently. As a promotional

 offer, they allow users to upload unlimited number of songs to their 

 online music library. However, after a year, they restrict

 the number of free songs to 10. In addition to the promotion, Amazon has

 pre-loaded 10 popular songs to the user library.

 

 So, ideally, you would like to store as many songs as you like, in your library,

 during the promotional offer and then reduce your library to hold only 10 songs.

 

 In this lab, we will implement a modified version of your Amazon music library.

 We will not store any information about the actual song like title, artists etc.

 Instead, we will store how many times a song was played.

 

 What is given

 ==============

 

 You are given an integer array containing, randomly intitalized

 how_many_times_played values for 10 popular songs that Amazon pre-loaded to your library.

 

 What you have to to do

 ======================

Download the starter file given as an attachment. 

 

 1. Create and intialize a dynamic array how_many_times_played_dyn

    and copy the contents of how_many_times_played to it ( 0.5 points )

 2. Implement the grow function ( 0.5 points )

    a. Ask the user how many songs he/she wants to add

    b. Randomly choose values for "the no of times played" for those many songs

       and add it to the how_many_times_played_dyn array

 3. Implement the shrink function ( 1 point )

    a. Shrink the how_many_times_played_dyn to contain only

        the first 10 elements

 4. Implement the shrink_sorted function ( 1 point ) - Extra Credit

    a. Sort the how_many_times_played_dyn array in descending order

    b. Shrink the array to contain only the first 10 elements

NOTE : For examples on how to create and grow a dynamic array, please refer

to the lecture notes from yesterday's class.