CS 162 Fall 2001 Assignment 7 –Vectors and Writing Generic Functions Using an existing class 100 points
Assigned: 10/29/2001
Due: 11/05/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:
A simplified Song class has been provided (song.h and song.cpp under Review on my WWW page). Create two function templates and a client program, as illustrated below. The program should get input about songs from a file (details below) 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). After all song info has been read in, ask the user for each song how much air play to give it (see illustration) – this should be validated. Ask the user for the length of the radio show to be programmed (a different kind of programming!), then choose songs to play on the show as described below. Show the songs chosen and the amount of time scheduled (as illustrated below). You must write function templates (and use them) to 1) display a collection of elements, and 2) pick a random element from a collection of elements.
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).
3) Songs to be played on the show are to determined
as follows – randomly choose which playlist to use – heavy, moderate or light.
The heavy list should be favored. For example, I gave the heavy list 4 chances
out of 7, the moderate list 2 chances out of 7, and the light list, 1 chance
out of 7 (the no play list got 0 chances. After a playlist has been chosen,
randomly select a song from that playlist – using your pick a random element
function template.
4) Random numbers within a range can be easily
generated. For example, to generate a number between 0 and 5 you can use the
expression: rand( ) % 6.
5) 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)
6) Use vectors in your main file, but your function
templates should be more general.
Hand-in:
1) Listing of the program
2) Disk with your .cpp file, and
your template .h file, and your working
.exe file. NAME YOUR PROGRAM FILE yourlastname7.cpp; Name your project
yourlastname7 so that the executable will be yourlastname7.exe. If you are
working in pairs, use both last names (e.g. redmondsmith7.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!
7)
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
For song: The
Tide is High by Blondie lasts 3:43
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: Stray
Cat Strut by Stray Cats lasts 4:15
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: Da,
Da, Da by Trio lasts 2:46
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song:
Middle of the Road by The Pretenders lasts 4:19
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song: Red
Skies by The Fixx lasts 3:12
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song: Do
you Really Want to Hurt Me by Culture Club lasts 3:36
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 3
For song:
Suddenly Last Summer by The Motels lasts 4:08
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 3
For song: Town
Called Malice by The Jam lasts 4:10
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song: Rio
by Duran Duran lasts 3:58
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: Never
Say Never by Romeo Void lasts 4:11
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: Radio
Free Europe by REM lasts 2:54
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song:
Dancing With Myself by Billy Idol lasts 3:19
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song:
Anthrax by Gang of Four lasts 2:11
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 3
For song: Call
Me by Blondie lasts 3:14
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: What
I Like About You by The Romantics lasts 3:32
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song:
Mickey by Toni Basil lasts 3:10
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 4
For song:
Electric Avenue by Eddy Grant lasts 4:12
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 5
answer must be
between 1 and 4. Please re-enter
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 6
answer must be
between 1 and 4. Please re-enter
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song:
Tainted Love / Where Did Our Love Go by Soft Cell lasts 4:19
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: Rock
This Town by Stray Cats lasts 3:43
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: The
Look of Love by ABC lasts 4:32
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song: The
Safety Dance by Men Without Hats lasts 4:57
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: I
Melt With You by Modern English lasts 4:21
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: Wake
Me Up Before You Go-Go by Wham! lasts 3:37
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 3
For song: If
You Leave by Orchestral Manoevres in the Dark lasts 5:05
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
For song: Love
Shack by The B-52's lasts 2:53
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 2
For song: You
Spin Me Round (Like a Record) by Dead or Alive lasts 3:23
Please enter how much we would like to
play this song 1) Heavy Play; 2) Moderate Play; 3) Light Play 4) No Play 1
Heavy Play:
Middle of the Road by The Pretenders lasts
4:19
Red Skies by The Fixx lasts 3:12
Town Called Malice by The Jam lasts 4:10
Radio Free Europe by REM lasts 2:54
What I Like About You by The Romantics
lasts 3:32
Electric Avenue by Eddy Grant lasts 4:12
The Look of Love by ABC lasts 4:32
If You Leave by Orchestral Manoevres in
the Dark lasts 5:05
You Spin Me Round (Like a Record) by Dead
or Alive lasts 3:23
Moderate Play:
The Tide is High by Blondie lasts 3:43
Stray Cat Strut by Stray Cats lasts 4:15
Da, Da, Da by Trio lasts 2:46
Rio by Duran Duran lasts 3:58
Never Say Never by Romeo Void lasts 4:11
Dancing With Myself by Billy Idol lasts
3:19
Call Me by Blondie lasts 3:14
Tainted Love / Where Did Our Love Go by
Soft Cell lasts 4:19
Rock This Town by Stray Cats lasts 3:43
The Safety Dance by Men Without Hats lasts
4:57
I Melt With You by Modern English lasts
4:21
Love Shack by The B-52's lasts 2:53
Low Play:
Do you Really Want to Hurt Me by Culture
Club lasts 3:36
Suddenly Last Summer by The Motels lasts
4:08
Anthrax by Gang of Four lasts 2:11
Wake Me Up Before You Go-Go by Wham! lasts
3:37
No Play:
Mickey by Toni Basil lasts 3:10
How many
minutes of show to plan? 60
Songs to play
on this show:
Wake Me Up Before You Go-Go by Wham! lasts
3:37
Do you Really Want to Hurt Me by Culture
Club lasts 3:36
Red Skies by The Fixx lasts 3:12
Call Me by Blondie lasts 3:14
Rock This Town by Stray Cats lasts 3:43
Town Called Malice by The Jam lasts 4:10
Wake Me Up Before You Go-Go by Wham! lasts
3:37
Electric Avenue by Eddy Grant lasts 4:12
Anthrax by Gang of Four lasts 2:11
The Tide is High by Blondie lasts 3:43
The Look of Love by ABC lasts 4:32
Middle of the Road by The Pretenders lasts
4:19
I Melt With You by Modern English lasts
4:21
Rock This Town by Stray Cats lasts 3:43
Wake Me Up Before You Go-Go by Wham! lasts
3:37
Total Time (in
seconds): 3347 (between 55 and 56 minutes )
(fill the rest with commercials)