diff --git a/ASD_Task_3.depend b/ASD_Task_3.depend index 831bfcc..b4fff67 100644 --- a/ASD_Task_3.depend +++ b/ASD_Task_3.depend @@ -52,3 +52,31 @@ "operation.h" "my_data.h" +1582369741 source:c:\users\asus\documents\github\asd_task_3\main.cpp + + "list.h" + "operation.h" + "my_data.h" + +1581957108 c:\users\asus\documents\github\asd_task_3\list.h + + "my_data.h" + +1582367462 c:\users\asus\documents\github\asd_task_3\my_data.h + + +1581956906 c:\users\asus\documents\github\asd_task_3\operation.h + "list.h" + +1582370026 source:c:\users\asus\documents\github\asd_task_3\list.cpp + "list.h" + "my_data.h" + +1582364652 source:c:\users\asus\documents\github\asd_task_3\my_data.cpp + "my_data.h" + +1582369763 source:c:\users\asus\documents\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..176e11c 100644 --- a/ASD_Task_3.layout +++ b/ASD_Task_3.layout @@ -2,37 +2,37 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/bin/Debug/ASD_Task_3.exe b/bin/Debug/ASD_Task_3.exe new file mode 100644 index 0000000..c843005 Binary files /dev/null and b/bin/Debug/ASD_Task_3.exe differ diff --git a/list.cpp b/list.cpp index fe0655c..01ecaca 100644 --- a/list.cpp +++ b/list.cpp @@ -1,14 +1,14 @@ #include "list.h" #include "my_data.h" +using namespace std; void createList(List &L) { /** * FS : set first(L) and last(L) with Null */ //-------------your code here------------- - your code here - - + L.first=NULL; + L.last=NULL; //---------------------------------------- } @@ -19,9 +19,13 @@ address allocate(infotype x) { address P; //-------------your code here------------- - your code here - - + P=new elmlist; + P->info.ID=x.ID; + P->info.name=x.name; + P->info.rank=x.rank; + P->info.score=x.score; + P->next=NULL; + P->prev=NULL; //---------------------------------------- return P; } @@ -31,8 +35,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here - + delete P; //---------------------------------------- } @@ -43,9 +46,14 @@ 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 (L.first==NULL){ + L.first=P; + L.last=P; + }else { + P->next=L.first; + L.first->prev=P; + L.first=P; + } //---------------------------------------- } @@ -55,8 +63,14 @@ 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 (L.first==NULL){ + L.first=P; + L.last=P; + }else { + L.last->next=P; + P->prev=L.last; + L.last=P; + } //---------------------------------------- } @@ -70,9 +84,10 @@ address findElm(List L, infotype x) { address P; //-------------your code here------------- - your code here - - + P=L.first; + while (P!=NULL && P->info.ID!=x.ID){ + P=P->next; + } //---------------------------------------- return P; } @@ -83,9 +98,16 @@ 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 (L.first==L.last){ + P=L.first; + L.first=NULL; + L.last=NULL; + }else if (L.first!=NULL){ + P=L.first; + L.first=P->next; + L.first->prev=NULL; + P->next=NULL; + } //---------------------------------------- } @@ -96,8 +118,16 @@ 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 (L.first!=NULL){ + P=L.last; + L.last=P->prev; + L.last->next=NULL; + P->prev=NULL; + }else if (L.first==L.last){ + P=L.first; + L.first=NULL; + L.last=NULL; + } //---------------------------------------- @@ -109,9 +139,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) + { + cout<info.ID<<" "<info.name<<" "<info.rank<<" "<info.score<next=Prec->next; + P->prev=Prec; + Prec->next->prev=P; + Prec->next=P; + } //---------------------------------------- } @@ -135,8 +173,14 @@ void deleteAfter(List &L, address Prec, address &P) { * is removed and pointed by pointer P */ //-------------your code here------------- - your code here + if (L.first!=NULL){ + P=Prec->next; + Prec->next = P->next; + P->next->prev = Prec; + P->next = NULL; + P->prev = NULL; + } //---------------------------------------- } diff --git a/list.h b/list.h index c21344f..c070520 100644 --- a/list.h +++ b/list.h @@ -23,9 +23,9 @@ using namespace std; * prev : address * > * -* Type List : < -* first : address -* last : address +* Type List : < +* first : address +* last : address * > * **/ @@ -37,14 +37,16 @@ typedef struct elmlist *address; struct elmlist{ //------------- your code here ----------- - + infotype info; + address next; + address prev; //---------------------------------------- }; struct List{ //------------- your code here ----------- - - + address first; + address last; //---------------------------------------- }; diff --git a/main.cpp b/main.cpp index 9e0b483..4124c85 100644 --- a/main.cpp +++ b/main.cpp @@ -21,6 +21,7 @@ int main() { void mainMenu() { address P; infotype X; + mytype member; /** * IS : List has been created * PR : prints menu to user @@ -50,8 +51,56 @@ void mainMenu() { switch(choice) { case 1: X = create_data(); - P = allocate(X); - insertFirst(L,P) + insertAndSort(L,X); + break; + case 2: + if (L.first!=NULL){ + cout<<"Data Member :"<>member.ID; + if (findElm(L,member)!=NULL){ + view_data(findElm(L,member)->info); + }else { + cout<<"ID Member tidak ditemukan"<>member.ID; + if (findElm(L,member)!=NULL){ + edit_data(findElm(L,member)->info); + }else { + cout<<"ID Member tidak ditemukan"<>member.ID; + if (findElm(L,member)!=NULL){ + deletebyID(L,member.ID); + cout<<"Data member telah dihapus"; + }else { + cout<<"ID Member tidak ditemukan"<>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.name; + cout<<"Masukkan Rank : "; + cin>>d.rank; + cout<<"Masukkan Score : "; + cin>>d.score; // =========================== } diff --git a/my_data.h b/my_data.h index 2937b48..bf6c39f 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 :MUH. FACHRUL HIDAYAT + STUDENT ID :1301194066 **/ 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..8f060c2 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..cee4bc8 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..2bd5b35 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..bca98b3 Binary files /dev/null and b/obj/Debug/operation.o differ diff --git a/operation.cpp b/operation.cpp index c2dc0b0..e1c2c5a 100644 --- a/operation.cpp +++ b/operation.cpp @@ -1,9 +1,11 @@ #include "list.h" #include "operation.h" #include "my_data.h" - -void insertAndSort(List &L, infotype x) { + + +void insertAndSort(List &L, infotype x) +{ /** * IS : List may be empty * PR : insert a new element into an already sorted-by-ID List L @@ -14,14 +16,35 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here - - + address P=L.first; + if (L.first==NULL) + { + insertFirst(L,allocate(x)); + } + else if (P->info.ID > x.ID) + { + insertFirst(L,allocate(x)); + } + else if (L.last->info.ID < x.ID) + { + insertLast(L,allocate(x)); + } + else + { + while (P!=NULL && P->info.ID < x.ID) + { + P=P->next; + } + P=P->prev; + insertAfter(L,P,allocate(x)); + } + cout<info.ID == id_x) + { + deleteFirst(L,P); + deallocate(P); + } + else if (L.last->info.ID == id_x) + { + deleteLast(L,P); + deallocate(P); + } + else + { + while (P != NULL && P->info.ID != id_x) + { + P = P->next; + } + P = P->prev; + deleteAfter(L,P,Prec); + deallocate(Prec); + } //---------------------------------------- } -void savePassedMember(List &L, List &L2){ +void savePassedMember(List &L, List &L2) +{ /** * IS : List L and L2 may be empty * FS : any element with score greater than 80 is moved to L2 */ address P; //-------------your code here------------- - your code here + address Q=L2.first; + P=L.first; + + while (P!=NULL) + { + if (Q==NULL) + { + if (P->info.score>=80) + { + insertLast(L2,P); + } + P=P->next; + } + else + { + if (Q->info.ID==P->info.ID) + { + Q=Q->next; + } + else if (P->info.score>=80) + { + insertLast(L2,P); + } + P=P->next; + } + } //---------------------------------------- }