Code app todo btl nhập môn lập trình

18 13 0
Code app todo btl nhập môn lập trình

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chuẩn đầu ra Sau khi hoàn thành bài tập lớn này, sinh viên ôn lại và sử dụng thành thục: • Các cấu trúc rẽ nhánh • Các cấu trúc lặp • Mảng 1 chiều và mảng 2 chiều • Xử lý chuỗi ký tự • Hàm và lời gọi hàm • Cấu trúc do người dùng tự định nghĩa (struct) 2 Dẫn nhập Ứng dụng Todo là một phần mềm hỗ trợ việc quản lý và theo dõi các công việc. Để sử dụng phần mềm, người dùng liệt kê các công việc và thời hạn để thực hiện công việc. Các công việc sẽ được biểu diễn dưới dạng một danh sách và có hiển thị các trạng thái như Hoàn thành, Đang thực hiện, hoặc Loại bỏ (Hình 1). Ứng dụng Todo giúp người dùng quản lý công việc cũng như không quên thực hiện các nhiệm vụ quan trọng. Trong bài tập lớn này, bạn sẽ hiện thực một Ứng dụng Todo đơn giản theo mô tả ở các Mục sau. 3 Yêu cầu ứng dụng Mục này nêu ra các yêu cầu để xây dựng một Ứng dụng Todo hoàn chỉnh. Để giải quyết các yêu cầu này, sinh viên phải hiện thực các hàm tương ứng theo mô tả yêu cầu. Mỗi yêu cầu có số điểm đi kèm biểu diễn số điểm tối đa đạt được nếu sinh viên hiện thực đúng yêu cầu.

enum CommandType getCommandType(char * command) { // TODO // Requirement 1: char firstWord[MAX_LENGTH_COMMAND+1]; sscanf(command, "%s", firstWord); if (strcmp(firstWord, "Add") == 0) { return ADD; } else if (strcmp(firstWord, "Edit") == 0) { return EDIT; } else if (strcmp(firstWord, "Show") == 0) { return SHOW; } else if (strcmp(firstWord, "Delete") == 0) { return DELETE; } else if (strcmp(firstWord, "Quit") == 0) { return QUIT; } return INVALID; } // Requirement 2: void getTitleFromAdd(const char* command, char* out_title) { sscanf(command, "Add [%[^]]", out_title); } void getDescriptionFromAdd(const char* command, char* out_description) { sscanf(command, "Add [%*[^]]] [%[^]]", out_description); } void getTimeFromAdd(const char* command, char* out_time) { sscanf(command, "Add [%*[^]]] [%*[^]]] [%[^]]", out_time); } // Requirement 3: int checkTitle(char *raw_title) { int titleLength = strlen(raw_title); int i; if (titleLength > 100) { return titleLength; } if (isspace(raw_title[0]) || isspace(raw_title[titleLength - 1])) { return 0; } for (i = 0; i < titleLength; i++) { char currentChar = raw_title[i]; if (!(isalpha(currentChar) || isdigit(currentChar) || isspace(currentChar) || currentChar == ',' || currentChar == '.' || currentChar == '-' || currentChar == ':' || currentChar == '|' || currentChar == '/')) { return i; } } return -1; } // Requirement 4: int checkDescription(char *raw_description) { int descriptionLength = strlen(raw_description); int i; if (descriptionLength > 200) { return descriptionLength; } if (isspace(raw_description[0]) || isspace(raw_description[descriptionLength - 1])) { return 0; } for (i = 0; i < descriptionLength; i++) { char currentChar = raw_description[i]; if (!(isalpha(currentChar) || isdigit(currentChar) || isspace(currentChar) || currentChar == ',' || currentChar == '.' || currentChar == '-' || currentChar == ':' || currentChar == '|' || currentChar == '/')) { return i; } } return -1; } int checkTime(char *raw_time) { char datetime1[MAX_LENGTH_TIME+1]; char datetime2[MAX_LENGTH_TIME+1]; int i = 0; while (raw_time[i] != '-') { datetime1[i] = raw_time[i]; i++; } datetime1[i] = '\0'; i++; int j = 0; while (raw_time[i] != '\0') { datetime2[j] = raw_time[i]; i++; j++; } datetime2[j] = '\0'; int hh1, mm1, dd1, mo1, yyyy1; if (sscanf(datetime1, "%d:%d|%d/%d/%d", &hh1, &mm1, &dd1, &mo1, &yyyy1) != 5) { return atoi("1100") + hh1; } if (hh1 < || hh1 > 23) { return atoi("1100") + hh1; } if (mm1 < || mm1 > 59) { return atoi("2100") + mm1; } if (yyyy1 23) { return atoi("1200") + hh2; } if (mm2 < || mm2 > 59) { return atoi("2200") + mm2; } if (yyyy2 max_days) { return atoi("3100") + dd1; } switch (mo2) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: max_days = 31; break; case 4: case 6: case 9: case 11: max_days = 30; break; case 2: if ((yyyy2 % == && yyyy2 % 100 != 0) || (yyyy2 % 400 == 0)) max_days = 29; else max_days = 28; break; default: return atoi("4200") + mo2; } if (dd2 < || dd2 > max_days) { return atoi("3200") + dd2; } if (yyyy2 < yyyy1 || (yyyy2 == yyyy1 && mo2 < mo1) || (yyyy2 == yyyy1 && mo2 == mo1 && dd2 < dd1) || (yyyy2 == yyyy1 && mo2 == mo1 && dd2 == dd1 && hh2 < hh1) || (yyyy2 == yyyy1 && mo2 == mo1 && dd2 == dd1 && hh2 == hh1 && mm2 < mm1)) { return 0; } return -1; } //Requirement 6: void getTitleFromEdit(char* command, char* out_title) { char* start = strstr(command, "title:["); if (start != NULL) { start += strlen("title:["); char* end = strchr(start, ']'); if (end != NULL) { strncpy(out_title, start, end - start); out_title[end - start] = '\0'; } } } void getDescriptionFromEdit(char* command, char* out_description) { char* start = strstr(command, "description:["); if (start != NULL) { start += strlen("description:["); char* end = strchr(start, ']'); if (end != NULL) { strncpy(out_description, start, end - start); out_description[end - start] = '\0'; } } } void getTimeFromEdit(char* command, char* out_time) { char* start = strstr(command, "time:["); if (start != NULL) { start += strlen("time:["); char* end = strchr(start, ']'); if (end != NULL) { strncpy(out_time, start, end - start); out_time[end - start] = '\0'; } } } // Requirement 7: int getNumFromCommand(char* command) { char* start = strchr(command, '#'); if (start == NULL) { return -1; } start++; int num = atoi(start); if (num no_tasks) // báo l?i n?u hàm in sai { return false; } for (i = num - 1; i < no_tasks - 1; i++) { strcpy(array_tasks[i].title, array_tasks[i + 1].title); strcpy(array_tasks[i].description, array_tasks[i + 1].description); strcpy(array_tasks[i].time, array_tasks[i + 1].time); array_tasks[i].status = array_tasks[i+1].status; } no_tasks ; //nó s? ?i ??n ??a chi l?u no_tasks th?c hi?n phép tính gi?m ?i return true; } // yêu c?u 19 int printWeekTime(struct Task * array_tasks, int no_tasks,char * date) { //t?o c?u trúc weektime struct week { int num; char week_title[MAX_LENGTH_TITLE+1]; char week_description[MAX_LENGTH_DESCRIPTION+1]; char week_time[MAX_LENGTH_TIME+1]; }; struct week *weektime[7][24]; return 1; } // Other functions

Ngày đăng: 29/12/2023, 20:16

Tài liệu cùng người dùng

Tài liệu liên quan