-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final Project - To do List
152 lines (137 loc) · 5.41 KB
/
Final Project - To do List
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct data {
int id;
char namaTugas[50], deskripsi[255];
int prioritas, status;
time_t waktuPencatatan;
struct data *next, *prev;
};
int id = 1;
int main() {
struct data *head, *tail, *repeat, *stay, *tampil;
int pilihan, ketemu;
head = malloc(sizeof(struct data));
head->prev = NULL;
head->next = NULL;
while(1) {
// replace
system("cls");
printf("====== Program : To Do List ====== \n");
printf("1. Tambah kegiatan\n");
printf("2. Tampilkan kegiatan\n");
printf("3. Update kegiatan (priority atau status) \n");
printf("4. Hapus kegiatan\n");
printf("5. Keluar\n");
printf("================== \n");
printf("Pilihan : "); scanf("%d",&pilihan);
if (pilihan == 1) {
tail = head;
while(tail->next!=NULL) tail = tail->next;
tail -> id = id;
id = id + 1;
printf("tugas ke - %d\n", tail->id);
printf("Nama tugas : "); fflush(stdin); gets(tail->namaTugas);
printf("Deskripsi tugas : \n"); fflush(stdin); gets(tail->deskripsi);
printf("prioritas (1-10) : "); scanf("%d",&tail->prioritas);
time(&tail -> waktuPencatatan);
tail -> status = 0;
repeat = malloc(sizeof(struct data));
tail->next = repeat;
repeat->prev = tail;
repeat->next = NULL;
}
else if (pilihan == 2) {
tampil = head;
while(tampil->next!=NULL) {
printf("--------------------------------------------------\n");
printf("Tugas ke - %d\n", tampil->id);
printf("Nama kegiatan : %s\n",tampil->namaTugas);
printf("Deskripsi : \n%s\n",tampil->deskripsi);
printf("Prioritas : %d\n",tampil->prioritas);
printf("dibuat pada : %s", ctime(&tampil->waktuPencatatan));
printf("status : ");
if (tampil->status == 0 ) printf("belum selesai\n");
else printf("selesai");
tampil = tampil->next;
}
}
else if (pilihan == 3) {
ketemu = 0;
int idTugas;
printf("id tugas yang ingin diupdate : "); scanf("%d",&idTugas);
tampil = head;
while(tampil->next!=NULL) {
if (tampil->id == idTugas) {
ketemu = 1;
break;
}
tampil = tampil->next;
}
if(ketemu==0) printf("Data tidak ditemukan! \n");
else {
printf("tugas ke - %d\n", tampil->id);
printf("Nama kegiatan : %s\n",tampil->namaTugas);
printf("prioritas (1-10) : from %d to? ", tampil->prioritas); scanf("%d", &tampil->prioritas);
printf("status (0 - not finish | 1 - done) from ");
if (tampil->status == 1 ) printf("done to?",tampil->status);
else printf("not finish to?",tampil->status);
scanf("%d", &tampil->status);
printf("\n\n");
printf("Data berhasil diupdate! \n");
printf("Tugas ke - %d\n", tampil->id);
printf("Nama kegiatan : %s\n",tampil->namaTugas);
printf("Deskripsi : \n%s\n",tampil->deskripsi);
printf("Prioritas : %d\n",tampil->prioritas);
printf("Waktu pencatatan : %s", ctime(&tampil->waktuPencatatan));
printf("status : %d\n\n",tampil->status);
}
tampil = head;
}
else if(pilihan == 4) {
ketemu = 0;
int idTugas;
printf("id tugas yang ingin dihapus : "); scanf("%d",&idTugas);
tampil = head;
if (head->id == idTugas) {
head = head->next;
head->prev = NULL;
printf("Tugas ke - %d\n", tampil->id);
printf("Nama kegiatan : %s\n",tampil->namaTugas);
printf("Deskripsi : \n%s\n",tampil->deskripsi);
printf("Prioritas : %d\n",tampil->prioritas);
printf("Waktu pencatatan : %s\n", ctime(&tampil->waktuPencatatan));
printf("status : %d\n\n",tampil->status);
free(tampil);
ketemu = 1;
} else {
while(tampil->next!=NULL){
if(tampil->id == idTugas) {
if (tampil->next == NULL) tampil->prev->next = NULL;
else {
tampil->prev->next = tampil->next;
tampil->next->prev = tampil->prev;
}
printf("Tugas ke - %d\n", tampil->id);
printf("Nama kegiatan : %s\n",tampil->namaTugas);
printf("Deskripsi : \n%s\n",tampil->deskripsi);
printf("Prioritas : %d\n",tampil->prioritas);
printf("Waktu pencatatan : %s\n", ctime(&tampil->waktuPencatatan));
printf("status : %d\n\n",tampil->status);
free(tampil);
ketemu = 1;
}
tampil = tampil->next;
}
}
if(ketemu==0) printf("Data tidak ditemukan! \n");
else printf("berhasil dihapus!\n");
tampil = head;
}
else if (pilihan == 5) return 0;
else printf("Pilihan yang anda masukkan salah!\n");
system("pause");
}
return 0;
}