-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3Shuffler2-algorithm.txt
244 lines (230 loc) · 7.65 KB
/
mp3Shuffler2-algorithm.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@copyrighted 1999 Valerie Colber
Full Name and Student ID Number: Kevin Jaewoo Lee 1989282
Course and section: COMSC-110-1572
1. Objective (1 sentence brief description of what this will do): The program randomly select and output titles in a loop until the user wishes to stop
2. Requirements (any and all requirements organized by input, processing, output, data):
INPUT (any data items to be input):
answer
PROCESSING (list of significant parts of the objective that will become the list of code blocks in program):
1. data definitions
2. user introduction
3. read input file
4.output prompt
5.save input file to list
6. add new score to list, if list is not full
7.determine whether it was played last 5 times
7.5 user answer
8.store the last 5 played songs
OUTPUT (list of anything output: introduction, data items, labels, prompts) :
-user introduction: introduction of objective, author, user instructions/rules
-prompt "play a song [Y/N]?: "
-label "Can not understand, I will just play another song "
DATA (list of all data items: definition, data type, formatting, or any other specifications):
ifstream fin;
const int MAX_SONGS = 200; // list capacity
-nSongs = 0; (integer)// initially empty
-songs[MAX_SONGS] (string)
-answer (character) // determine to play a song or not
-srand(time(0)); rand(); //"seed" the random number generator
-random = 0 + rand() % 200 (integer) //random song
-i = (integer) // index loop
-deque<Music> music // create a empty list
-Music amusic // to put values in the amusic
3. Algorithm instructions (recipe)
***data
10 set int MAX_SONGS = 200
20 set nSongs = 0
30 set songs
40 set answer
41 set i
42 set structure Music contains field name
***user introduction
50 output introduction: objective, author, instructions/rules
***read input file
60 open songs.txt file
***output prompt
70 output prompt "play a song [Y/N]?: "
80 input answer
90 set random = 0 + rand() % 200 (integer)
***save input file to list
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[nSongs++] = aSongs then skip to 100
***determine whether it was played last 5 times
120 set count = 0
130 set random = random number
140 if music size is 0 then skip to instruction 200
150 set i =0
160 if music[i].name is equal to songs[random] then count = count + 1
170 i = i+ 1
180 if i is less than music size then skip to instruction 160
190 if count is not equal to 0 then skip to instruction 120
***user answer
200 if answer is equal to y or Y output songs[random] then skip to 230
210 if answer is equal to n or N skip to instruction 260
220 else ouput prompt "Can not understand, I will just play another song " skip to 70
***store the last 5 played songs
230 amusic.name = songs[random]
240 add songs[random] at the end of the music struct
250 if music size is bigger than 5 then remove value from the front of the list
255 skip to instruction 70
260 end program
4. Test cases (list purpose of each test case, any input values, and expected results)
Test case #1:
purpose: simple example
input :
expected results :
play a song [Y/N]?: y
Ted Weems - Heartaches.mp3
play a song [Y/N]?: y
Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3
play a song [Y/N]?: n
10 set int MAX_SONGS = 200
20 set nSongs = 0
30 set songs
40 set answer
***user introduction
50 output introduction: objective, author, instructions/rules
***read input file
60 open songs.txt file
70 output prompt "play a song [Y/N]?: "
80 input answer =y
90 set random = 0 + rand() % 200 (integer)
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[0] = aSongs then skip to 100
x200 times because of MAX_SONGS
110 false
120 set count = 0
130 set random number
140 true skip to instuction 200
200 true output songs[random] = Ted Weems - Heartaches.mp3 then skip to 230
230 amusic.name = Ted Weems - Heartaches.mp3
240 add songs[random] at the end of the music struct = Ted Weems - Heartaches.mp3
250 false
255 skip to instruction 70
70 output prompt "play a song [Y/N]?: "
80 input answer =y
90 set random = 0 + rand() % 200 (integer)
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[0] = aSongs then skip to 100
x200 times because of MAX_SONGS
110 false
120 set count = 0
130 set random = random number
140 false
150 set i =0
160 false
170 i = 1
180 false
190 false
200 true output songs[random] = Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3 then skip to 230
230 amusic.name = Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3
240 add songs[random] at the end of the music struct = Ted Weems - Heartaches.mp3 , Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3
250 false
255 skip to instruction 70
70 output prompt "play a song [Y/N]?: "
80 input answer = n
90 set random = 0 + rand() % 200 (integer)
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[0] = aSongs then skip to 100
x200 times because of MAX_SONGS
110 false
120 set count = 0
130 set random = random number
140 false
150 set i =0
160 false
170 i = 1
180 true then skip to 160
160 false
170 i = 2
180 false
190 false
200 false
210 true then skip to instruction 260
260 end program
999 END
Test case #2:
purpose: invalid input
input :
expected results :
play a song [Y/N]?: y
Ted Weems - Heartaches.mp3
play a song [Y/N]?: y
Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3
play a song [Y/N]?: k
Can not understand, I will just play another song
play a song [Y/N]?:
999END
10 set int MAX_SONGS = 200
20 set nSongs = 0
30 set songs
40 set answer
***user introduction
50 output introduction: objective, author, instructions/rules
***read input file
60 open songs.txt file
70 output prompt "play a song [Y/N]?: "
80 input answer =y
90 set random = 0 + rand() % 200 (integer)
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[0] = aSongs then skip to 100
x200 times because of MAX_SONGS
110 false
120 set count = 0
130 set random number
140 true skip to instuction 200
200 true output songs[random] = Ted Weems - Heartaches.mp3 then skip to 230
230 amusic.name = Ted Weems - Heartaches.mp3
240 add songs[random] at the end of the music struct = Ted Weems - Heartaches.mp3
250 false
255 skip to instruction 70
70 output prompt "play a song [Y/N]?: "
80 input answer =y
90 set random = 0 + rand() % 200 (integer)
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[0] = aSongs then skip to 100
x200 times because of MAX_SONGS
110 false
120 set count = 0
130 set random = random number
140 false
150 set i =0
160 false
170 i = 1
180 false
190 false
200 true output songs[random] = Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3 then skip to 230
230 amusic.name = Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3
240 add songs[random] at the end of the music struct = Ted Weems - Heartaches.mp3 , Mario Lanza-Loveliest Night Of The Year (Rca Victor).mp3
250 false
255 skip to instruction 70
70 output prompt "play a song [Y/N]?: "
80 input answer = k
90 set random = 0 + rand() % 200 (integer)
100 set aSongs
105 fileinput aSongs
110 if nSongs is less than MAX_SONGS then songs[0] = aSongs then skip to 100
x200 times because of MAX_SONGS
110 false
120 set count = 0
130 set random = random number
140 false
150 set i =0
160 false
170 i = 1
180 true then skip to 160
160 false
170 i = 2
180 false
190 false
200 false
210 false
220 else ouput prompt "Can not understand, I will just play another song " skip to 70
70 output prompt "play a song [Y/N]?: "
...