diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..0e4420a 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,22 @@ "operation.h" "my_data.h" +1582381821 source:d:\github\latihan\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582330300 d:\github\latihan\asd_task_3\list.h + + "my_data.h" + +1582381690 d:\github\latihan\asd_task_3\my_data.h + + +1582381876 source:d:\github\latihan\asd_task_3\operation.cpp + "list.h" + "operation.h" + "my_data.h" + +1582327055 d:\github\latihan\asd_task_3\operation.h + "list.h" + diff --git a/ASD_Task_3.layout b/ASD_Task_3.layout index 17b1801..ea8cfdb 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,37 +2,37 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/list.cpp b/list.cpp index fe0655c..68ea3a7 100644 --- a/list.cpp +++ b/list.cpp @@ -6,8 +6,8 @@ void createList(List &L) { * FS : set first(L) and last(L) with Null */ //-------------your code here------------- - your code here + first(L) = NULL; //---------------------------------------- } @@ -19,8 +19,10 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here + P = new elmlist; + info(P) = x; + next(P) = NULL; //---------------------------------------- return P; @@ -31,20 +33,27 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here + delete P; //---------------------------------------- } + void insertFirst(List &L, address P) { /** * IS : List L may be empty * FS : element pointed by P became the first element in List L */ //-------------your code here------------- - your code here + if(first(L) != NULL){ + next(P) = first(L); + first(L) = P; + } + else{ + first(L) = P; + } //---------------------------------------- } @@ -55,8 +64,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){ + address Q = first(L); + while(next(Q) != NULL){ + Q = next(Q); + } + next(Q) = P; + } + else{ + insertFirst(L, P); + } //---------------------------------------- } @@ -67,11 +85,22 @@ address findElm(List L, infotype x) { * FS : returns element with info.ID = x.ID, return Null if such ID is not found */ - + int ID; address P; //-------------your code here------------- - your code here + P = first(L); + while (P != NULL){ + if(info(P).ID != x.ID){ + P = next(P); + } + else if(info(P).ID == x.ID){ + return P; + } + else{ + return NULL; + } + } //---------------------------------------- return P; @@ -83,8 +112,15 @@ 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) != NULL){ + P = first(L); + first(L) = next(P); + next(P) = NULL; + } + else{ + first(L) = NULL; + } //---------------------------------------- @@ -96,8 +132,17 @@ 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 + P = first(L); + if(first(L) != NULL){ + while(next(next(P)) != NULL){ + P = next(P); + } + next(P) = NULL; + } + else{ + first(L) = NULL; + } //---------------------------------------- @@ -109,8 +154,20 @@ 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; + if(first(L) != NULL){ + P = first(L); + while(P != NULL){ + cout<< "------------------------"< * -* Type List : < -* first : address -* last : address +* Type List : < +* first : address +* last : address * > * **/ @@ -37,13 +37,14 @@ typedef struct elmlist *address; struct elmlist{ //------------- your code here ----------- - + infotype info; + address next; //---------------------------------------- }; struct List{ //------------- your code here ----------- - + address first; //---------------------------------------- }; diff --git a/main.cpp b/main.cpp index 9e0b483..0e8b3dd 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,8 @@ using namespace std; void mainMenu(); List L, L_passed; -int main() { +int main() +{ createList(L); createList(L_passed); @@ -18,7 +19,8 @@ int main() { return 0; } -void mainMenu() { +void mainMenu() +{ address P; infotype X; /** @@ -35,7 +37,8 @@ void mainMenu() { */ //-------------your code here------------- int choice; - do { + do + { cout<<"Menu"<>choice; - switch(choice) { - case 1: - X = create_data(); - P = allocate(X); - insertFirst(L,P) - break; - } - } while(true); + P = allocate(X); + insertFirst(L,P) + break; - //---------------------------------------- + case 1 : + X = create_data(); + P = allocate(X); + insertFirst(L,P) + if (findElm(L, info(P)) == NULL) + { + insertFirst(L, P); + } + break; + case 2: + printInfo(L); + break; + case 3: + cout << "Masukkan ID yang ingin dicari : "; + cin >> X.ID; + P = findElm(L, X); + if (P != NULL) + { + view_data(info(P)); + } + else + { + cout << "DATA TIDAK DITEMUKAN!\n"; + } + break; + case 4: + cout << "Masukkan ID yang ingin diedit : "; + cin >> X.ID; + P = findElm(L, X); + if (P != NULL) + { + edit_data(info(P)); + } + else + { + cout << "DATA TIDAK DITEMUKAN!\n"; + } + break; + case 5: + cout << "Masukkan ID yang ingin didelete : "; + cin >> X.ID; + if (findElm(L, X) != NULL) + { + deletebyID(L, X.ID); + } + else + { + cout << "DATA TIDAK DITEMUKAN" << endl; + } + 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..6160839 100644 --- a/my_data.cpp +++ b/my_data.cpp @@ -1,10 +1,10 @@ - + #include "my_data.h" /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF-43-o5 + NAME : Muhammad Sulthon Asramanggala + STUDENT ID : 130194008 **/ mytype create_data() { @@ -15,7 +15,15 @@ mytype create_data() { mytype d; // =========================== // YOUR CODE HERE - your code here + + cout<< "ID mahasiswa : "; + cin<< d.ID; + cout<< "Nama Mahasiswa : "; + cin<< d.name; + cout << "Rangking Mahasiswa : "; + cin >> d.ranking; + cout << "Score Mahasiswa : "; + cin >> d.score; @@ -33,6 +41,13 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE your code here + cout << " ID : " << d.ID<> d.name; + cout << "Ranking Baru : "; + cin >> d.ranking; + cout << "Score Baru : "; + cin >> d.score; diff --git a/my_data.h b/my_data.h index 2937b48..975624d 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 : Muhammad Sulthon Asramanggala + STUDENT ID : 1301194008 **/ struct mytype { @@ -20,7 +20,11 @@ struct mytype { */ //================================================= // YOUR CODE STARTS HERE - your code here + + int ID; + string name; + int rangking; + float score; // YOUR CODE ENDS HERE //================================================= @@ -29,6 +33,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..25c2669 Binary files /dev/null and b/obj/Debug/list.o differ diff --git a/obj/Debug/operation.o b/obj/Debug/operation.o new file mode 100644 index 0000000..0a1a375 Binary files /dev/null and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..be2681f 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,38 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here + address P; + address Q; + P = allocate(x); + if(first(L) == NULL){ + insertFirst(L, P); + } + else{ + Q = findElm(L, info(P)); + if(Q == NULL){ + address last = first(L); + while(next(last) != NULL){ + last = next(last); + } + if(info(P).ID <= info(first(L)).ID){ + insertFirst(L, P); + } + else if(info(P).ID >= info(first(L)).ID){ + insertLast(L, P); + } + else{ + Q = first(L); + while(info(next(Q)).ID < info(P).ID){ + Q = next(Q); + } + insertAfter(L, Q, P); + } + } + else{ + cout << "ID duplikat" << endl; + } + } //---------------------------------------- } @@ -29,8 +59,28 @@ void deletebyID(List &L, int id_x) { address Prec, P; //-------------your code here------------- - your code here + infotype x; + x.ID = id_x; + P = findElm(L, x); + if(first(L) != NULL){ + if(P == first(L)){ + deleteFirst(L, P); + deallocate(P); + } + else if(next(P) == NULL){ + deleteLast(L,P); + deallocate(P); + } + else{ + Prec = first(L); + while(next(Prec) != P){ + Prec = next(Prec); + } + deleteAfter(L, Prec, P); + } + + } //---------------------------------------- } @@ -43,8 +93,18 @@ void savePassedMember(List &L, List &L2){ */ address P; //-------------your code here------------- - your code here - + List tmp; + createList(tmp); + while(first(L) != NULL){ + deleteFirst(L,P); + if(info(P).score > 80){ + insertAndSort(L2, info(P)); + } + else{ + insertAndSort(tmp, info(P)); + } + } + L = tmp; //---------------------------------------- }