forked from ASD-ADF/ASD_Task_4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.cpp
More file actions
119 lines (106 loc) · 2.65 KB
/
player.cpp
File metadata and controls
119 lines (106 loc) · 2.65 KB
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
#include "player.h"
#include <ctime>
int randomInt(int max_int) {
/** YOU DON'T NEED TO MODIFY THIS */
srand(time(NULL));
return (rand() % max_int) + 1;
}
void printInfo(List L) {
/**
* PR : menampilkan informasi ID, nama, dan lokasi file
* YOU DON'T NEED TO MODIFY THIS
*/
address Q = first(L);
do {
cout<<"name : "<<info(Q).name<<endl
<<"ID : "<<info(Q).ID<<endl
<<"location: "<<info(Q).location<<endl;
Q = next(Q);
} while(Q!=first(L));
cout<<"==============================================="<<endl;
}
void playMusic(address P) {
/**
* PR : memainkan lagu yang ditunjuk oleh pointer P
* YOU DON'T NEED TO MODIFY THIS
*/
string filename = info(P).location+"/"+info(P).name;
cout<<"playing "<<filename<<endl;
PlaySound(TEXT(filename.c_str()), NULL, SND_FILENAME);
_sleep(500); //delay 0.5 second
}
void shuffleList(List &L) {
/**
* PR : mengacak isi (elemen) dari list L
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------
address P = first(L);
int i = 0;
do
{
P = next(P);
i++;
}
while (P != first(L));
while ( i > 0)
{
P = first(L);
int j = randomInt(i);
while( j != 0)
{
P = next(P);
j--;
}
address Q = P;
deleteAfter(L, prev(P), Q);
insertFirst(L, Q);
i--;
cout<<"UNDER MAIN TENIS"<<endl;
}
//----------------------------------------
}
void playRepeat(List &L, int n) {
/**
* PR : memainkan seluruh lagu di dalam list
* dari lagu pertama hingga terakhir sebanyak n kali
*/
//------------- YOUR CODE HERE -------------
address P;
int i;
i = 0;
P = first(L);
while (i < n )
{
do
{
playMusic(P);
P = next(P);
}
while (P != first(L));
i++;
cout<<"UNDER MAIN TENIS"<<endl;
//----------------------------------------
}
void deleteMusicByID(List &L, infotype x) {
/**
* IS : list L mungkin kosong
* PR : menerima input user untuk ID lagu yang ingin dihapus
* jika ID lagu ditemukan, hapus (deallocate) lagu dari list
* FS : elemen dengan ID yang dicari dideallocate
*/
//------------- YOUR CODE HERE -------------
address P,Q;
P = prev(P);
if (next(P) == first(L))
{
deleteFirst(L,P);
}
else if (info(next(P)).ID == x.ID )
{
deleteAfter(L,P,Q);
deallocate(Q);
}
cout<<"UNDER MAIN TENIS"<<endl;
//----------------------------------------
}