CS 162 Fall 2001                                Assignment 10 – Queues (and modifying previously written code ?!?!?)                     100 points

 

Assigned: 11/26/2001

Due: 12/04/2001 at the start of class.

Pre-Lab (Do Before Lab): Bring an empty (or nearly empty) disk. Plan out steps needed for program.

Pairs: You may work in pairs if you want. Note, during the course of the semester, you cannot pair with any one person more than twice. If you work in a pair, turn in ONE copy that is the work of both of you, with both of your names on it.  Each member of the pair will receive the same grade for that lab.  In such a partnership, students must share as equally as possible the work and learning.  Working together with truly shared effort and learning can be a positive experience. However, simply giving/receiving code from someone defeats the learning process. If substantial parts of a program are taken from non-partners, that is plagiarism. The copier and copyee will each receive a zero.

Main Assignment:

                We return to the simplified song class from Assignment 7. Create a client program as illustrated below.  The program should get input about songs from a file (as in Assignment 7) along with some input from the user. Data input from the file cannot be reprompted (however any bad data should be flagged (present an error message to cerr). In this assignment, all songs will have the same priority – you can store them in a vector or list or whatever is convenient for you. Then we will go through cycles of planning songs and playing them. As planning is done, songs will be added to a queue of songs to be played. You MUST use a queue for this purpose. Songs will later be played in the exact order that they are added to the queue. The cycles will continue as long as the user indeicates that they are not done. During each cycle, you will ask the user for how many songs to plan, and plan that many, then ask them for how many minutes worth to be be played – and play that much music. As each song is added to the planning queue, say so. As each song is played, report that. Since songs won’t fit into time exactly, keep any extra unused time that can be carried over to the next cycle. Likewise, any songs not played will stay on the queue for the next cycle. Finally, show how many seconds (and minutes) of music were played, and show songs remaining on the queue. 

Details:

1)       If you change song.h and/or song.cpp,  make sure you hand them in as well. (I don’t think you should have to – I don’t think you should even have to look at song.cpp)

2)       I have provided (under Review on my www page) a function mygetline for getting a line of data from a file. You are encouraged to use this (you can include it in your main file – but give me credit). Use this as you did for Assignment 7.

3)       Determining songs to be played on the show is determined differently than in Assignment 7. However, if you created the template in Assignment 7 as I recommended – picking a random element from a container – then you can probably reuse it  for this program. 

4)       One sample set of songs has been provided (songlist.txt under Review on my WWW page). The format of any input file should be: on the first line, the number of songs to follow, then, for each song, a line for title, a line for artist, then a number of minutes and a number of seconds (e.g. 3  45  would mean 3 minutes and 45 seconds)

5)       Make sure that if not enough songs are planned for the time requested that the program handles this gracefully – see sample interaction below.

6)       Validate – Y/N answer and number of songs (from 1 to 50 valid) and number of minutes (from 1 to 180). Sample interaction doesn’t show any user errors on these, but they should still be validated.

7)       YOU MUST USE QUEUES FOR THE SONGS IN LINE TO BE PLAYED!!.

Hand-in:

    1) Listing of the program

 2) Disk with your .cpp file, and your template .h file if you use it,  the song.h and song.cpp, and your working .exe file. NAME YOUR PROGRAM FILE yourlastname10.cpp; Name your project yourlastname10 so that the executable will be yourlastname10.exe. If you are working in pairs, use both last names (e.g. redmondsmith10.cpp)

Miscellaneous:

1) If you have any questions about what should be done, please ask!!

2) MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors). Test it more than once - I will!

8)       Remember: Indentation, meaningful variable names, symbolic constants, and meaningful comments. Weaknesses in any of these could result in points off. Also make sure you put YOUR NAME(s), section, and e-mail address in comments at the beginning of the program.

Sample Interaction:

Please enter name of file containing songs songlist.txt

Reading song: The Tide is High by Blondie lasts 3:43

Reading song: Stray Cat Strut by Stray Cats lasts 4:15

Reading song: Da, Da, Da by Trio lasts 2:46

Reading song: Middle of the Road by The Pretenders lasts 4:19

Reading song: Red Skies by The Fixx lasts 3:12

Reading song: Do you Really Want to Hurt Me by Culture Club lasts 3:36

Reading song: Suddenly Last Summer by The Motels lasts 4:08

Reading song: Town Called Malice by The Jam lasts 4:10

Reading song: Rio by Duran Duran lasts 3:58

Reading song: Never Say Never by Romeo Void lasts 4:11

Reading song: Radio Free Europe by REM lasts 2:54

Reading song: Dancing With Myself by Billy Idol lasts 3:19

Reading song: Anthrax by Gang of Four lasts 2:11

Reading song: Call Me by Blondie lasts 3:14

Reading song: What I Like About You by The Romantics lasts 3:32

Reading song: Mickey by Toni Basil lasts 3:10

Reading song: Electric Avenue by Eddy Grant lasts 4:12

Reading song: Tainted Love / Where Did Our Love Go by Soft Cell lasts 4:19

Reading song: Rock This Town by Stray Cats lasts 3:43

Reading song: The Look of Love by ABC lasts 4:32

Reading song: The Safety Dance by Men Without Hats lasts 4:57

Reading song: I Melt With You by Modern English lasts 4:21

Reading song: Wake Me Up Before You Go-Go by Wham! lasts 3:37

Reading song: If You Leave by Orchestral Manoevres in the Dark lasts 5:05

Reading song: Love Shack by The B-52's lasts 2:53

Reading song: You Spin Me Round (Like a Record) by Dead or Alive lasts 3:23

 

How many songs to plan? 3

Adding Mickey by Toni Basil lasts 3:10 to end of queue

Adding Town Called Malice by The Jam lasts 4:10 to end of queue

Adding Electric Avenue by Eddy Grant lasts 4:12 to end of queue

How many minutes to play before replanning? 10

Playing Mickey by Toni Basil lasts 3:10

Playing Town Called Malice by The Jam lasts 4:10

Extra seconds for now: 160

 

Are you done with the simulation?  (y or n): n

How many songs to plan? 3

Adding Suddenly Last Summer by The Motels lasts 4:08 to end of queue

Adding Town Called Malice by The Jam lasts 4:10 to end of queue

Adding The Safety Dance by Men Without Hats lasts 4:57 to end of queue

How many minutes to play before replanning? 10

Playing Electric Avenue by Eddy Grant lasts 4:12

Playing Suddenly Last Summer by The Motels lasts 4:08

Playing Town Called Malice by The Jam lasts 4:10

Extra seconds for now: 10

 

Are you done with the simulation?  (y or n): n

How many songs to plan? 3

Adding Anthrax by Gang of Four lasts 2:11 to end of queue

Adding Red Skies by The Fixx lasts 3:12 to end of queue

Adding The Tide is High by Blondie lasts 3:43 to end of queue

How many minutes to play before replanning? 10

Playing The Safety Dance by Men Without Hats lasts 4:57

Playing Anthrax by Gang of Four lasts 2:11

Extra seconds for now: 182

 

Are you done with the simulation?  (y or n): n

How many songs to plan? 3

Adding Love Shack by The B-52's lasts 2:53 to end of queue

Adding Dancing With Myself by Billy Idol lasts 3:19 to end of queue

Adding Call Me by Blondie lasts 3:14 to end of queue

How many minutes to play before replanning? 10

Playing Red Skies by The Fixx lasts 3:12

Playing The Tide is High by Blondie lasts 3:43

Playing Love Shack by The B-52's lasts 2:53

Extra seconds for now: 194

 

Are you done with the simulation?  (y or n): n

How many songs to plan? 3

Adding Dancing With Myself by Billy Idol lasts 3:19 to end of queue

Adding Do you Really Want to Hurt Me by Culture Club lasts 3:36 to end of queue

Adding Middle of the Road by The Pretenders lasts 4:19 to end of queue

How many minutes to play before replanning? 20

Playing Dancing With Myself by Billy Idol lasts 3:19

Playing Call Me by Blondie lasts 3:14

Playing Dancing With Myself by Billy Idol lasts 3:19

Playing Do you Really Want to Hurt Me by Culture Club lasts 3:36

Playing Middle of the Road by The Pretenders lasts 4:19

Need More Songs - Extra seconds for now: 327

 

Are you done with the simulation?  (y or n): n

How many songs to plan? 10

Adding If You Leave by Orchestral Manoevres in the Dark lasts 5:05 to end of queue

Adding Do you Really Want to Hurt Me by Culture Club lasts 3:36 to end of queue

Adding Rio by Duran Duran lasts 3:58 to end of queue

Adding Tainted Love / Where Did Our Love Go by Soft Cell lasts 4:19 to end of queue

Adding Da, Da, Da by Trio lasts 2:46 to end of queue

Adding I Melt With You by Modern English lasts 4:21 to end of queue

Adding Rock This Town by Stray Cats lasts 3:43 to end of queue

Adding Da, Da, Da by Trio lasts 2:46 to end of queue

Adding If You Leave by Orchestral Manoevres in the Dark lasts 5:05 to end of queue

Adding Suddenly Last Summer by The Motels lasts 4:08 to end of queue

How many minutes to play before replanning? 10

Playing If You Leave by Orchestral Manoevres in the Dark lasts 5:05

Playing Do you Really Want to Hurt Me by Culture Club lasts 3:36

Playing Rio by Duran Duran lasts 3:58

Extra seconds for now: 168

 

Are you done with the simulation?  (y or n): y

Total Time (in seconds) of Songs Played: 4032 (between 67 and 68 minutes)

Songs left waiting to be played: 

   Tainted Love / Where Did Our Love Go by Soft Cell lasts 4:19

   Da, Da, Da by Trio lasts 2:46

   I Melt With You by Modern English lasts 4:21

   Rock This Town by Stray Cats lasts 3:43

   Da, Da, Da by Trio lasts 2:46

   If You Leave by Orchestral Manoevres in the Dark lasts 5:05

   Suddenly Last Summer by The Motels lasts 4:08