Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ASD_Task_4.depend
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@
"player.h"
<ctime>

1582872441 source:c:\mingw\c++ program\asd_task_4\list.cpp
"list.h"

1582637383 c:\mingw\c++ program\asd_task_4\list.h
<string>
<windows.h>
<iostream>

1582871510 source:c:\mingw\c++ program\asd_task_4\main.cpp
"player.h"
"list.h"
<conio.h>

1582628103 c:\mingw\c++ program\asd_task_4\player.h
"list.h"

1582872225 source:c:\mingw\c++ program\asd_task_4\player.cpp
"player.h"
<ctime>

20 changes: 10 additions & 10 deletions ASD_Task_4.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="4763" topLine="177" />
<Cursor1 position="189" topLine="0" />
</Cursor>
</File>
<File name="player.h" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="4940" topLine="0" />
</Cursor>
</File>
<File name="list.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="list.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2436" topLine="0" />
<Cursor1 position="270" topLine="9" />
</Cursor>
</File>
<File name="player.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="player.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="253" topLine="39" />
<Cursor1 position="342" topLine="0" />
</Cursor>
</File>
<File name="list.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="player.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="270" topLine="0" />
<Cursor1 position="2651" topLine="12" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added bin/Debug/ASD_Task_4.exe
Binary file not shown.
91 changes: 80 additions & 11 deletions list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void createList(List &L) {
* FS : first(L) diset Nil
*/
//------------- YOUR CODE HERE -------------

L.first = NULL;
//----------------------------------------
}

Expand All @@ -17,7 +17,12 @@ address allocate(infotype x) {

address P = NULL;
//------------- YOUR CODE HERE -------------

P = new elmlist;
P -> info.ID = x.ID;
P -> info.location = x.location;
P -> info.name = x.name;
P -> next = NULL;
P -> prev = NULL;
//----------------------------------------
return P;
}
Expand All @@ -27,7 +32,7 @@ void deallocate(address &P) {
* FS : menghapus elemen yang ditunjuk oleh P (delete)
*/
//------------- YOUR CODE HERE -------------

delete(P);
//----------------------------------------
}

Expand All @@ -37,7 +42,17 @@ void insertFirst(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen pertama pada List L
*/
//------------- YOUR CODE HERE -------------

if (L.first == NULL) {
P -> next = P;
P -> prev = P;
L.first = P;
} else {
P -> next = L.first;
P -> prev = L.first -> prev;
L.first -> prev -> next = P;
L.first -> prev = P;
L.first = P;
}
//----------------------------------------
}

Expand All @@ -47,7 +62,14 @@ void insertLast(List &L, address P) {
* FS : elemen yang ditunjuk P menjadi elemen terakhir pada List L
*/
//------------- YOUR CODE HERE -------------

if (L.first == NULL) {
insertFirst(L, P);
} else {
P -> next = L.first;
P -> prev = L.first -> prev;
L.first -> prev -> next = P;
L.first -> prev = P;
}
//----------------------------------------
}

Expand All @@ -60,7 +82,13 @@ address findElmByID(List L, infotype x) {

address P = NULL;
//------------- YOUR CODE HERE -------------

P = L.first;
do {
P = P -> next;
} while (P != L.first && P -> info.ID != x.ID);
if (P == L.first && P -> info.ID != x.ID) {
return NULL;
}
//----------------------------------------
return P;
}
Expand All @@ -74,7 +102,13 @@ address findElmByName(List L, infotype x) {

address P = NULL;
//------------- YOUR CODE HERE -------------

P = L.first;
do {
P = P -> next;
} while (P != L.first && P -> info.name != x.name);
if (P == L.first && P -> info.name != x.name) {
return NULL;
}
//----------------------------------------
return P;
}
Expand All @@ -85,7 +119,19 @@ void deleteFirst(List &L, address &P) {
* FS : elemen pertama di dalam List L dilepas dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

if (L.first == NULL) {
P = L.first;
P -> next = NULL;
P -> prev = NULL;
L.first = NULL;
} else {
P = L.first;
L.first = P -> next;
L.first -> prev = P -> prev;
P -> prev -> next = L.first;
P -> next = NULL;
P -> prev = NULL;
}
//----------------------------------------
}

Expand All @@ -95,7 +141,15 @@ void deleteLast(List &L, address &P) {
* FS : elemen tarakhir di dalam List L dilepas dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

if (L.first == NULL) {
deleteFirst(L, P);
} else {
P = L.first -> prev;
P -> prev -> next = L.first;
L.first -> prev = P -> prev;
P -> next = NULL;
P -> prev = NULL;
}
//----------------------------------------
}

Expand All @@ -106,7 +160,14 @@ void insertAfter(List &L, address &Prec, address P) {
* ditunjuk pointer Prec
*/
//------------- YOUR CODE HERE -------------

if (L.first == NULL) {
insertFirst(L, P);
} else {
P -> next = Prec -> next;
P -> prev = Prec;
Prec -> next -> prev = P;
Prec -> next = P;
}
//----------------------------------------

}
Expand All @@ -117,7 +178,15 @@ void deleteAfter(List &L, address &Prec, address &P) {
* dan disimpan/ditunjuk oleh P
*/
//------------- YOUR CODE HERE -------------

if (Prec -> next == L.first) {
deleteFirst(L, P);
} else {
P = Prec -> next;
P -> next -> prev = Prec;
Prec -> next = P -> next;
P -> next = NULL;
P -> prev = NULL;
}
//----------------------------------------
}

6 changes: 4 additions & 2 deletions list.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ typedef struct elmlist *address;

struct elmlist {
//------------- YOUR CODE HERE -----------

infotype info;
address next;
address prev;

//----------------------------------------
};

struct List {
//------------- YOUR CODE HERE -----------

address first;

//----------------------------------------
};
Expand Down
29 changes: 22 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main() {

x.ID = index_ID++;
x.location = "asset";
x.name = "re.wav";
x.name = "do'.wav";
P = allocate(x);
insertLast(L,P);

Expand Down Expand Up @@ -96,7 +96,8 @@ address inputMusic() {
* YOU DON'T NEED TO MODIFY THIS
*/
cout<<"input music filename (.wav) : ";
cin>>x.name;
cin.get();
getline(cin, x.name);
cout<<"input music location "<<endl<<"(write - for default /asset location) :";
cin>>x.location;
if(x.location=="-") {
Expand All @@ -123,6 +124,8 @@ void runMenu(int menu) {
// insert last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;
P = inputMusic();
insertLast(L, P);
//input music
//insertLast()

Expand All @@ -143,7 +146,8 @@ void runMenu(int menu) {
// play last music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

P = L.first -> prev;
playMusic(P);
//----------------------------------------
break;
case 6:
Expand All @@ -154,15 +158,23 @@ void runMenu(int menu) {
P = findElmByName(L, x);
if(P != NULL){
cout<<"music found"<<endl;
} else {
cout<<"music NOT found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
case 7:
// search music by ID
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

cout<<"input music ID : ";
cin >> x.ID;
P = findElmByID(L, x);
if(P != NULL){
cout<<"music found"<<endl;
} else {
cout<<"music NOT found"<<endl;
}
//----------------------------------------
cout<<"press enter";getche();
break;
Expand All @@ -183,7 +195,10 @@ void runMenu(int menu) {
// play previous music
//------------- YOUR CODE HERE -------------
cout<<"UNDER MAIN TENIS"<<endl;

if (P != NULL) {
P = P -> prev;
playMusic(P);
}
//----------------------------------------
break;
case 11:
Expand All @@ -202,7 +217,7 @@ void runMenu(int menu) {
case 13:
// delete music by ID
cout<<"input music ID : ";
cin>>x.name;
cin>>x.ID;
deleteMusicByID(L, x);
cout<<"press enter";getche();
break;
Expand Down
Binary file added obj/Debug/list.o
Binary file not shown.
Binary file added obj/Debug/main.o
Binary file not shown.
Binary file added obj/Debug/player.o
Binary file not shown.
36 changes: 33 additions & 3 deletions player.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "player.h"
#include <ctime>

int randomInt(int max_int) {
int randomInt(int max_int) {
/** YOU DON'T NEED TO MODIFY THIS */
srand(time(NULL));
return (rand() % max_int) + 1;
Expand Down Expand Up @@ -43,6 +43,24 @@ void shuffleList(List &L) {
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------
address P = L.first;
int jumlah = 0;
do {
P = P -> next;
jumlah++;
} while (P != L.first);
while (jumlah > 0) {
P = L.first;
int k = randomInt(jumlah);
while (k != 0) {
P = P -> next;
k--;
}
address Q = P;
deleteAfter(L, P -> prev, Q);
insertFirst(L, Q);
jumlah--;
}

cout<<"UNDER MAIN TENIS"<<endl;

Expand All @@ -55,7 +73,13 @@ void playRepeat(List &L, int n) {
* dari lagu pertama hingga terakhir sebanyak n kali
*/
//------------- YOUR CODE HERE -------------

address P = L.first;
for (int i = 0; i < n; i++) {
do {
playMusic(P);
P = P -> next;
} while (P != L.first);
}
cout<<"UNDER MAIN TENIS"<<endl;

//----------------------------------------
Expand All @@ -69,7 +93,13 @@ void deleteMusicByID(List &L, infotype x) {
* FS : elemen dengan ID yang dicari dideallocate
*/
//------------- YOUR CODE HERE -------------

address P;
if (L.first != NULL) {
if (findElmByID(L, x) != NULL) {
deleteAfter(L, findElmByID(L, x) -> prev, P);
deallocate(P);
}
}
cout<<"UNDER MAIN TENIS"<<endl;

//----------------------------------------
Expand Down