From efe666aa62bf5fc62d933db2709de25d12e43285 Mon Sep 17 00:00:00 2001 From: vincentiusar Date: Wed, 19 Feb 2020 00:50:59 +0700 Subject: [PATCH 1/3] last summary commit 90% accurate. add all .cpp file and .h file --- .vscode/settings.json | 5 +++ list.cpp | 96 +++++++++++++++++++++++++++++++++---------- list.h | 9 ++-- main.cpp | 43 ++++++++++++++++++- my_data.cpp | 27 ++++++++---- my_data.h | 11 +++-- operation.cpp | 47 +++++++++++++++++---- 7 files changed, 190 insertions(+), 48 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cba2e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/list.cpp b/list.cpp index fe0655c..c941c89 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; + last(L) == NULL; //---------------------------------------- } @@ -19,8 +19,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,7 +36,7 @@ void deallocate(address &P) { * FS : delete element pointed by P */ //-------------your code here------------- - your code here + delete P; //---------------------------------------- @@ -43,7 +48,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 (first(L) != NULL) { + next(P) = first(L); + prev(first(L)) = P; + first(L) = P; + } else { + first(L) = P; + last(L) = P; + } //---------------------------------------- @@ -55,7 +67,9 @@ void insertLast(List &L, address P) { * FS : element pointed by P became the last element in List L */ //-------------your code here------------- - your code here + next(last(L)) = P; + prev(P) = last(L); + last(L) = P; //---------------------------------------- @@ -70,7 +84,10 @@ 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); + } //---------------------------------------- @@ -83,10 +100,17 @@ 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 if (first(L) != NULL) { + P = first(L); + first(L) = next(P); + next(P) = NULL; + prev(first(L)) = NULL; + } //---------------------------------------- } @@ -96,9 +120,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 (last(L) != NULL) { + P = last(L); + last(L) = prev(P); + prev(P) = NULL; + next(last(L)) = NULL; + } else if (first(L) == last(L)) { + P = first(L); + first(L) = NULL; + last(L) = NULL; + } //---------------------------------------- } @@ -109,8 +140,12 @@ 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 << endl; //---------------------------------------- } @@ -123,7 +158,16 @@ void insertAfter(List &L, address Prec, address P) { * pointed by pointer Prec */ //-------------your code here------------- - your code here + if (first(L) == NULL) { + insertFirst(L, P); + } else if (first(L) != last(L) && Prec != NULL) { + next(P) = next(Prec); + P -> prev = Prec; + prev(next(Prec)) = P; + next(Prec) = P; + } else if (Prec != NULL) { + insertLast(L, P); + } //---------------------------------------- @@ -135,9 +179,17 @@ void deleteAfter(List &L, address Prec, address &P) { * is removed and pointed by pointer P */ //-------------your code here------------- - your code here - + if (first(L) == last(L) && Prec != NULL) { + deleteFirst(L, P); + } else if (next(Prec) != last(L) && Prec != NULL) { + P = next(Prec); + next(Prec) = next(P); + prev(next(P)) = Prec; + next(P) = NULL; + prev(P) = NULL; + } else if (Prec != NULL) { + deleteLast(L, P); + } //---------------------------------------- -} - +} \ No newline at end of file diff --git a/list.h b/list.h index c21344f..0894909 100644 --- a/list.h +++ b/list.h @@ -37,13 +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; //---------------------------------------- }; @@ -61,7 +64,7 @@ void insertLast(List &L, address P); void deleteFirst(List &L, address &P); void deleteLast(List &L, address &P); void insertAfter(List &L, address Prec, address P); -void deleteAfter(List&L, address Prec, address &P); +void deleteAfter(List &L, address Prec, address &P); // define search-by-ID function and view procedure address findElm(List L, infotype x); diff --git a/main.cpp b/main.cpp index 9e0b483..650b3b0 100644 --- a/main.cpp +++ b/main.cpp @@ -51,10 +51,49 @@ void mainMenu() { 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; + deletebyID(L, X.ID); + break; + case 6: + savePassedMember(L, L_passed); + break; + case 7: + printInfo(L_passed); + break; + } + if (choice == 0) { break; } } while(true); //---------------------------------------- -} +} \ No newline at end of file diff --git a/my_data.cpp b/my_data.cpp index 68b9d77..eeb1dce 100644 --- a/my_data.cpp +++ b/my_data.cpp @@ -1,10 +1,9 @@ - #include "my_data.h" /** - CLASS : - NAME : - STUDENT ID : + CLASS : IF - 43 - 05 + NAME : Vincentius Arnold Fridolin + STUDENT ID : 1301190221 **/ mytype create_data() { @@ -15,9 +14,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 ranking : "; + cin >> d.rank; + cout << "Masukkan score : "; + cin >> d.score; // =========================== @@ -32,8 +36,8 @@ void view_data(mytype d) { // =========================== // YOUR CODE HERE - your code here + cout << d.ID << " - " << d.name << " - "<< d.rank << " - " << d.score << endl; @@ -50,7 +54,12 @@ void edit_data(mytype &d) { // =========================== // YOUR CODE HERE - your code here + cout << "Masukkan pergantian nama : "; + cin >> d.name; + cout << "Masukkan pergantian rank : "; + cin >> d.rank; + cout << "Masukkan pergantian score : "; + cin >> d.score; diff --git a/my_data.h b/my_data.h index 2937b48..61e7689 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 : Vincentius Arnold Fridolin + STUDENT ID : 1301190221 **/ struct mytype { @@ -20,7 +20,10 @@ struct mytype { */ //================================================= // YOUR CODE STARTS HERE - your code here + int ID; + string name; + int rank; + float score; // YOUR CODE ENDS HERE //================================================= diff --git a/operation.cpp b/operation.cpp index c2dc0b0..6319d9b 100644 --- a/operation.cpp +++ b/operation.cpp @@ -14,9 +14,17 @@ void insertAndSort(List &L, infotype x) { */ //-------------your code here------------- - your code here - - + address p, p1; + p = first(L); + if (p == NULL || info(p).ID > x.ID) { + insertFirst(L, allocate(x)); + } else if (findElm(L, x) == NULL) { + while (p != NULL && info(p).ID < x.ID) { + p1 = p; + p = next(p); + } + insertAfter(L, p1, allocate(x)); + } //---------------------------------------- } @@ -29,8 +37,17 @@ void deletebyID(List &L, int id_x) { address Prec, P; //-------------your code here------------- - your code here - + P = first(L); + if (P == first(L) && id_x == info(P).ID) { + deleteFirst(L, P); + } else { + while (P != NULL) { + if (id_x == info(P).ID && first(L) != last(L)) { + deleteAfter(L, prev(P), P); + } + P = next(P); + } + } //---------------------------------------- } @@ -43,8 +60,22 @@ 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); + } + } //---------------------------------------- -} +} \ No newline at end of file From 2c81ffcdea7644cb2db56e020c54fb9c0fc0400e Mon Sep 17 00:00:00 2001 From: vincentiusar Date: Wed, 19 Feb 2020 01:08:08 +0700 Subject: [PATCH 2/3] last commit --- main.cpp | 6 +++++- operation.cpp | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index 650b3b0..62d2cb1 100644 --- a/main.cpp +++ b/main.cpp @@ -81,7 +81,11 @@ void mainMenu() { case 5: cout << "Masukkan ID yang ingin didelete : "; cin >> X.ID; - deletebyID(L, X.ID); + if (findElm(L, X) != NULL) { + deletebyID(L, X.ID); + } else { + cout << "DATA TIDAK DITEMUKAN" << endl; + } break; case 6: savePassedMember(L, L_passed); diff --git a/operation.cpp b/operation.cpp index 6319d9b..0f0e252 100644 --- a/operation.cpp +++ b/operation.cpp @@ -38,16 +38,16 @@ void deletebyID(List &L, int id_x) { address Prec, P; //-------------your code here------------- P = first(L); - if (P == first(L) && id_x == info(P).ID) { - deleteFirst(L, P); - } else { - while (P != NULL) { - if (id_x == info(P).ID && first(L) != last(L)) { - deleteAfter(L, prev(P), P); - } - P = next(P); - } - } + if (P == first(L) && id_x == info(P).ID) { + deleteFirst(L, P); + } else { + while (P != NULL) { + if (id_x == info(P).ID && first(L) != last(L)) { + deleteAfter(L, prev(P), P); + } + P = next(P); + } + } //---------------------------------------- } From 5e883a07f96d09e4233808c38c8a6e2ed32a512b Mon Sep 17 00:00:00 2001 From: Vincentius Ar <58662886+vincentiusar@users.noreply.github.com> Date: Wed, 19 Feb 2020 01:09:19 +0700 Subject: [PATCH 3/3] Update main.cpp --- main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 62d2cb1..e35729b 100644 --- a/main.cpp +++ b/main.cpp @@ -82,10 +82,10 @@ void mainMenu() { cout << "Masukkan ID yang ingin didelete : "; cin >> X.ID; if (findElm(L, X) != NULL) { - deletebyID(L, X.ID); - } else { - cout << "DATA TIDAK DITEMUKAN" << endl; - } + deletebyID(L, X.ID); + } else { + cout << "DATA TIDAK DITEMUKAN" << endl; + } break; case 6: savePassedMember(L, L_passed); @@ -100,4 +100,4 @@ void mainMenu() { } while(true); //---------------------------------------- -} \ No newline at end of file +}