diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..6097524 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,31 @@ "operation.h" "my_data.h" +1582385350 source:d:\tugas kuliah\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582381225 d:\tugas kuliah\github\asd_task_3\list.h + + "my_data.h" + +1582385243 d:\tugas kuliah\github\asd_task_3\my_data.h + + +1582385547 source:d:\tugas kuliah\github\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + +1582266085 d:\tugas kuliah\github\asd_task_3\operation.h + "list.h" + +1582385561 source:d:\tugas kuliah\github\asd_task_3\my_data.cpp + "my_data.h" + +1582385903 source:d:\tugas kuliah\github\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + diff --git a/ASD_Task_3.layout b/ASD_Task_3.layout index 17b1801..90cc74e 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,39 +2,39 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_3.exe b/bin/Debug/ASD_Task_3.exe new file mode 100644 index 0000000..1ed95b1 Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..6b9224f 100644 --- a/list.cpp +++ b/list.cpp @@ -6,9 +6,8 @@ void createList(List &L) { * FS : set first(L) and last(L) with Null */ //-------------your code here------------- - your code here - - + first(L) = NULL; + last(L) = NULL; //---------------------------------------- } @@ -19,9 +18,13 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here - - + P = new elmlist; + info(P).ID = x.ID; + info(P).Name = x.Name; + info(P).Rank = x.Rank; + info(P).score = x.score; + next(P) = NULL; + prev(P) = NULL; //---------------------------------------- return P; } @@ -31,8 +34,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here - + delete P; //---------------------------------------- } @@ -43,7 +45,17 @@ void insertFirst(List &L, address P) { * FS : element pointed by P became the first element in List L */ //-------------your code here------------- - your code here + if (first(L) == NULL && last(L) == NULL) + { + first(L) = P; + last(L) = P; + } + else + { + next(P) = first(L); + prev(first(L)) = P; + first(L) = P; + } //---------------------------------------- @@ -55,7 +67,17 @@ void insertLast(List &L, address P) { * FS : element pointed by P became the last element in List L */ //-------------your code here------------- - your code here + if (first(L) == NULL && last(L) == NULL) + { + first(L) = P; + last(L) = P; + } + else + { + prev(P) = last(L); + next(last(L)) = P; + last(L) = P; + } //---------------------------------------- @@ -70,9 +92,11 @@ address findElm(List L, infotype x) { address P; //-------------your code here------------- - your code here - - + P = first(L); + while (P != NULL && info(P).ID != x.ID) + { + P = next(P); + } //---------------------------------------- return P; } @@ -83,10 +107,19 @@ void deleteFirst(List &L, address &P) { * FS : first element in List L is removed and is pointed by P */ //-------------your code here------------- - your code here - - - + if (first(L) == last(L)) + { + P = first(L); + first(L) = NULL; + last(L) = NULL; + } + else + { + P = first(L); + first(L) = next(P); + next(P) = NULL; + prev(first(L)) = NULL; + } //---------------------------------------- } @@ -96,7 +129,19 @@ void deleteLast(List &L, address &P) { * FS : last element in List L is removed and is pointed by P */ //-------------your code here------------- - your code here + if (last(L) != NULL ) + { + P = last(L); + last(L) = prev(P); + prev(P) = NULL; + next(last(L)) = NULL; + } + else + { + P = first(L); + first(L) = NULL; + last(L) = NULL; + } @@ -109,8 +154,13 @@ void printInfo(List L) { * call the view_data function from my_data.h to print the info */ //-------------your code here------------- - your code here - + address P = first(L); + while (P != NULL) + { + view_data(info(P)); + P = next(P); + } + cout< -* -* Type List : < -* first : address -* last : address -* > -* -**/ - - - typedef mytype infotype; typedef struct elmlist *address; -struct elmlist{ - //------------- your code here ----------- - - //---------------------------------------- +struct elmlist +{ + infotype info; + address next; + address prev; }; - -struct List{ - //------------- your code here ----------- - - - //---------------------------------------- -}; - + struct List + { + address first; + address last; + }; // define a function and a procedure to allocate and deallocate an element list diff --git a/main.cpp b/main.cpp index 9e0b483..74158bd 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,7 @@ int main() { void mainMenu() { address P; - infotype X; + infotype x; /** * IS : List has been created * PR : prints menu to user @@ -49,9 +49,84 @@ void mainMenu() { cin>>choice; switch(choice) { case 1: - X = create_data(); - P = allocate(X); - insertFirst(L,P) + { + x = create_data(); + P = allocate(x); + insertFirst(L,P); + break; + } + case 2 : + { + printInfo(L); + break; + } + case 3 : + { + cout<<"ID yang dicari :"; + cin>> x.ID; + address temu ; + temu = findElm(L,x); + if ( temu != NULL) + { + view_data(info(P)); + } + else + { + cout<<"Maaf data tidak ditemukan"<> x.ID; + address ubah; + ubah = findElm(L,x); + if ( ubah != NULL) + { + edit_data(info(P)); + } + else + { + cout<<"Maaf ID anda tidak dapat diedit."<>a.ID; + if ( cari == first(L)) + { + deleteFirst(L,cari); + } + else if ( cari == last(L)) + { + deleteLast(L, cari); + } + else + { + deleteAfter(L, prev(cari), cari); + } + cout<<"Penghapusan Berhasil"; + break; + } + case 6 : + { + savePassedMember(L,L_passed); + break; + } + case 7 : + { + printInfo(L_passed); + break; + } + } + if (choice == 0) + { break; } } while(true); diff --git a/my_data.cpp b/my_data.cpp index 68b9d77..024384c 100644 --- a/my_data.cpp +++ b/my_data.cpp @@ -1,10 +1,10 @@ - + #include "my_data.h" /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF - 43 - 05 + NAME : Berliana Shafa Wardani + STUDENT ID : 1301194181 **/ mytype create_data() { @@ -15,10 +15,14 @@ mytype create_data() { mytype d; // =========================== // YOUR CODE HERE - your code here - - - + cout<<"Masukkan ID : "; + cin>> d.ID; + cout<<"Masukkan Nama :"; + cin>> d.Name; + cout << "Masukkan Rank : "; + cin>> d.Rank; + cout<< "Masukkan Score : "; + cin>> d.score; // =========================== return d; @@ -32,10 +36,10 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here - - - + cout<<"ID :"<< d.ID; + cout<<"NAMA:"<< d.Name; + cout <<" RANK : "<< d.Rank; + cout<< " SCORE: "<> d.Name; + cout << "Masukkan update Rank : "; + cin>> d.Rank; + cout<< "Masukkan update Score : "; + cin>> d.score; // =========================== diff --git a/my_data.h b/my_data.h index 2937b48..db4d22b 100644 --- a/my_data.h +++ b/my_data.h @@ -5,9 +5,9 @@ using namespace std; /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF - 43 -05 + NAME : BERLIANA SHAFA WARDANI + STUDENT ID : 1301194181 **/ struct mytype { @@ -20,8 +20,10 @@ struct mytype { */ //================================================= // YOUR CODE STARTS HERE - your code here - + int ID; + string Name; + int Rank; + float score; // YOUR CODE ENDS HERE //================================================= }; @@ -29,6 +31,6 @@ struct mytype { mytype create_data(); void view_data(mytype d); -void edit_data(mytype &d); +void edit_data(mytype &d); #endif // MY_DATA_H_INCLUDED diff --git a/obj/Debug/list.o b/obj/Debug/list.o new file mode 100644 index 0000000..f7e5215 Binary files /dev/null and b/obj/Debug/list.o differ diff --git a/obj/Debug/main.o b/obj/Debug/main.o new file mode 100644 index 0000000..cb69f61 Binary files /dev/null and b/obj/Debug/main.o differ diff --git a/obj/Debug/my_data.o b/obj/Debug/my_data.o new file mode 100644 index 0000000..869ce3b Binary files /dev/null and b/obj/Debug/my_data.o differ diff --git a/obj/Debug/operation.o b/obj/Debug/operation.o new file mode 100644 index 0000000..cba7ea3 Binary files /dev/null and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..d61154a 100644 --- a/operation.cpp +++ b/operation.cpp @@ -1,7 +1,7 @@ #include "list.h" #include "operation.h" #include "my_data.h" - + void insertAndSort(List &L, infotype x) { /** @@ -14,8 +14,27 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here - + address P = allocate(x); + if (first(L) == NULL || info(first(L)).ID > x.ID) + { + insertFirst(L,P); + } + else + { + address Q = first(L); + while ( next(Q) != NULL && x.ID >= info(next(Q)).ID ) + { + Q = next(Q); + } + if (info(Q).ID != x.ID) + { + insertAfter(L,Q,P); + } + else + { + insertLast(L,P); + } + } //---------------------------------------- } @@ -29,7 +48,25 @@ void deletebyID(List &L, int id_x) { address Prec, P; //-------------your code here------------- - your code here + P = first(L); + if (id_x == info(P).ID) + { + deleteFirst(L,P); + } + else if ( info(last(L)).ID == id_x) + { + deleteLast(L,P); + } + else + { + address Q; + while (next(Q) != NULL && info(next(Q)).ID != id_x) + { + Q = next(Q); + } + Prec = Q; + deleteAfter(L, Prec,P); + } //---------------------------------------- @@ -43,8 +80,29 @@ void savePassedMember(List &L, List &L2){ */ address P; //-------------your code here------------- - your code here - + P = first(L); + address Q = P; + while (Q != NULL) + { + P = Q; + if ( info(P).score > 80) + { + insertAndSort(L2, info(P)); + Q = next(Q); + if (prev(P) == NULL) + { + deleteFirst(L,P); + } + else + { + deleteAfter(L,prev(P), P); + } + } + else + { + Q = next(Q); + } + } //---------------------------------------- }