diff --git a/README.md b/README.md index 5617242..b16eaae 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 本系统是程序设计与问题求解课程设计项目,实现了库存零件 CSV 格式数据文件的读取和保存,以及数据的增删改查(CRUD)、排序和图表显示等功能。项目采用 C 语言编程实现,在 VS Code 集成开发环境(IDE)中用 GCC 进行编译。系统采用模块化设计,程序结构清晰,采用菜单驱动的命令行界面,操作便捷,能够用 CSV 格式读取和保存数据,通用性强,能够用图表展示数据,直观清楚。 -下载地址:https://gitee.com/wangqian12345/students +下载地址:https://bdgit.educoder.net/pzghsoly5/test.git 项目开发过程中采用 Kanban(看板)进行任务管理和分工协作,并使用 Git 对程序代码和文档进行版本管理。任务分工情况如下: @@ -325,7 +325,7 @@ a: No such file or directory 上述各模块通过主程序(main)进行调用,系统模块图如下。 -![系统模块图](images/module.drawio.svg) +![main.drawio](images/main.drawio.svg) 各模块的主要功能如下: diff --git a/daima b/daima new file mode 100644 index 0000000..b714bf2 --- /dev/null +++ b/daima @@ -0,0 +1,413 @@ +#include +#include +#include + + +//ͼ洢ṹ +struct book{ + int id;//ͼ + char name[20];//ͼ + char author[20];//ͼ + float price;//ͼ۸ + struct book *next; // ָһͼ +}*books; + + +/////////////////// +// ûģ // + +// ϵͳʼ,ȡļڴ +void init(); +// ʾ˵ +void display_menu(); +// ѡ˵,ӦĹܺ +void make_choice(); +// ȷϲ +void confirm(); +// ˳ϵͳ,ͷڴ,ݵļ +void quit(); + +/////////////////// +// ݴģ // + +// ļȡݵڴ +void read_data(); +// ڴݵļ +void save_data(); +// ӡͼϢ +void print_data(); +// ͼŲѯͼϢ +book *find(int id); +// ѯͼϢ +void query_data(); +// ͼϢ +void add_data(); +// ͼϢ +void update_data(); +// ɾͼϢ +void delete_data(); +// ͼϢ +void sort_data(); +// ͼ +void make_chart(); + + +///////////// +int main() +{ + display_menu(); + make_choice(); + return 0; +} + + + +// ûģ // +// ϵͳʼ,ȡļڴ +void init() +{ + read_data(); +} +// ʾ˵ +void display_menu() +{ + printf("*************************\n"); + printf("***** ͼϵͳ *****\n"); + printf("*************************\n"); + printf("1. ӡͼϢ\n"); + printf("2. ѯͼϢ\n"); + printf("3. ͼ\n"); + printf("4. ͼϢ\n"); + printf("5. ɾͼϢ\n"); + printf("6. ͼ\n"); + printf("7. ͼ\n"); + printf("0. ˳ϵͳ\n"); + printf("ѡ:"); +} +// ѡ˵,ӦĹܺ +void make_choice() +{ + int choice; + scanf("%d", &choice); + confirm(); + switch(choice) + { + case 1: + print_data(); // ӡͼϢ + break; + case 2: + query_data(); // ѯͼϢ + break; + case 3: + add_data(); // ͼ + break; + case 4: + update_data();// ͼϢ + break; + case 5: + delete_data();// ɾͼϢ + break; + case 6: + sort_data(); // ͼ + break; + case 7: + make_chart(); // ͼ + break; + case 0: + quit(); // ˳ϵͳ + break; + default: + printf("Чѡ,ѡ:"); + break; + } +} +// ȷϲ +void confirm() +{ + char choice; + + printf("ȷҪִиò?(Y/N):"); + scanf(" %c", &choice); + + if(choice == 'Y' || choice == 'y') + { + printf("ɹִ!\n"); + } + else if(choice == 'N' || choice == 'n') + { + printf("ȡ!\n"); + } + else + { + printf(",(Y/N):"); + confirm(); // ݹԼ + } +} +// ˳ϵͳ,ͷڴ,ݵļ +void quit() +{ + char choice; + + printf("ȷҪ˳ϵͳ?(Y/N):"); + scanf(" %c", &choice); + + if(choice == 'Y' || choice == 'y') + { + save_data(); // ݵļ + printf("ѱ,ϵͳ˳!\n"); + exit(0); // ˳ϵͳ + } + else if(choice == 'N' || choice == 'n') + { + printf("˳ȡ!\n"); + } + else + { + printf(",(Y/N):"); + quit(); // ݹԼ + } +} + + + +// ݴģ// +// ļȡݵڴ +void read_data() +{ + FILE *fp; + struct book *head, *p; + + if((fp = fopen("books.dat", "rb")) == NULL) + { + printf("ļʧ!\n"); + exit(0); + } + + head = NULL; + while(!feof(fp)) + { + p = (struct book*)malloc(sizeof(struct book)); + fread(p, sizeof(struct book), 1, fp); + p->next = head; + head = p; + } + + fclose(fp); // رļ + + // ͷָΪȫֱ,ʹ + books = head; +} +// ڴݵļ +void save_data() +{ + FILE *fp; + struct book *p; + + if((fp = fopen("books.dat", "wb")) == NULL) + { + printf("ļʧ!\n"); + exit(0); + } + + p = books; // ȫͷʼ + while(p != NULL) + { + fwrite(p, sizeof(struct book), 1, fp); + p = p->next; + } + + fclose(fp); +} + + + +// ӡͼϢ +void print_data() +{ + struct book *p; + + p = books; // ȫͷʼ + while(p != NULL) + { + printf("ͼ:%d\n", p->id); + printf("ͼ:%s\n", p->name); + printf("ͼ:%s\n", p->author); + printf("ͼ۸:%.2f\n", p->price); + printf("----------------------\n"); + p = p->next; + } +} +// ͼŲѯͼϢ +book *find(int id) +{ + struct book *p; + + p = books; // ȫͷʼ + while(p != NULL) + { + if(p->id == id) + return p; // ҵͼָ + p = p->next; + } + return NULL; // δҵؿָ *p; + + +} +// ѯͼϢ +void query_data() +{ + int id; + struct book *p; + + printf("Ҫѯͼ:"); + scanf("%d", &id); + + p = find(id); // ұΪidͼ + if(p != NULL) + { + printf("ͼϢ:\n"); + printf("ͼ:%d\n", p->id); + printf("ͼ:%s\n", p->name); + printf("ͼ:%s\n", p->author); + printf("ͼ۸:%.2f\n", p->price); + } + else + { + printf("ûҵΪ%dͼ!\n", id); + } +} +// ͼϢ +void add_data() +{ + struct book *p, *q; + + p = (struct book*)malloc(sizeof(struct book)); + + printf("ͼϢ:\n"); + printf("ͼ:"); + scanf("%d", &p->id); + printf("ͼ:"); + scanf("%s", p->name); + printf("ͼ:"); + scanf("%s", p->author); + printf("ͼ۸:"); + scanf("%f", &p->price); + + q = books; + while(q != NULL && p->id > q->id) + q = q->next; + + p->next = q; // ָһڵ + books = p; // ½ڵΪͷ + + printf("ͼϢӳɹ!\n"); +} +// ͼϢ +void update_data() +{ + int id; + struct book *p; + + printf("Ҫ޸ĵͼ:"); + scanf("%d", &id); + + p = find(id); // ұΪidͼ + if(p != NULL) + { + printf("޸ĺͼϢ:\n"); + printf("ͼ:"); + scanf("%s", p->name); + printf("ͼ:"); + scanf("%s", p->author); + printf("ͼ۸:"); + scanf("%f", &p->price); + + printf("ͼϢ޸ijɹ!\n"); + } + else + { + printf("ûҵΪ%dͼ!\n", id); + } +} +// ɾͼϢ +void delete_data() +{ + int id; + struct book *p, *q; + + printf("Ҫɾͼ:"); + scanf("%d", &id); + + p = books; + q = NULL; + while(p != NULL && p->id != id) + { + q = p; + p = p->next; + } + if(p != NULL) // ҵýڵ + { + if(q == NULL) // һڵ + books = p->next; + else + q->next = p->next; + + free(p); + printf("ͼϢɾɹ!\n"); + } + else + { + printf("ûҵΪ%dͼ!\n", id); + } +} +// ͼϢ +void sort_data() +{ + struct book *p, *q; // ڵָ + struct book temp; // ʱͼṹ + + p = books; + while(p != NULL) + { + q = p->next; + while(q != NULL) + { + if(p->id > q->id) // ڵ + { + temp = *p; + *p = *q; + *q = temp; + } + q = q->next; + } + p = p->next; + } + printf("ͼϢɹ!\n"); +} +// ͼ +void make_chart() +{ + struct book *p; + char name[20]; + int i, n; + float price; + + printf("Ҫɵͼ:"); + scanf("%d", &n); + + for(i=1; i<=n; i++) + { + p = (struct book*)malloc(sizeof(struct book)); + + sprintf(name, "ͼ%d", i); // ͼ + p->id = i; // ͼ + strcpy(p->name, name); // ͼ + strcpy(p->author, ""); // + price = (i+1)*10.0; // ۸ + p->price = price; // ͼ۸ + + p->next = books; // ½ڵָԭͷ + books = p; // ½ڵΪͷ + } + printf("ͼϢɳɹ!\n"); +} \ No newline at end of file diff --git a/picture/main.drawio.svg b/picture/main.drawio.svg new file mode 100644 index 0000000..cc0b24f --- /dev/null +++ b/picture/main.drawio.svg @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/picture/make_chart.drawio.svg b/picture/make_chart.drawio.svg new file mode 100644 index 0000000..1e5c307 --- /dev/null +++ b/picture/make_chart.drawio.svg @@ -0,0 +1,151 @@ + + + + + + + + + +
+
+
+

+ make_chart +

+
+
+
+
+ + make_chart + +
+
+ + + + + + +
+
+
+ + 打印图书信息 + +
+
+
+
+ + 打印图书信息 + +
+
+ + + + + + + + +
+
+
+ 是否打印完全? +
+
+
+
+ + 是否打印完全? + +
+
+ + + + +
+
+
+ N +
+
+
+
+ + N + +
+
+ + + + +
+
+
+ Y +
+
+
+
+ + Y + +
+
+ + + + +
+
+
+ + 打印成功 + +
+
+
+
+ + 打印成功 + +
+
+ + + + + + +
+
+
+ + 打印结束后换行继续循环 + +
+
+
+
+ + 打印结束后换行继续循环 + +
+
+ +
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/picture/printf_data.drawio.svg b/picture/printf_data.drawio.svg new file mode 100644 index 0000000..b50790a --- /dev/null +++ b/picture/printf_data.drawio.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/picture/query_data.drawio.svg b/picture/query_data.drawio.svg new file mode 100644 index 0000000..24e4764 --- /dev/null +++ b/picture/query_data.drawio.svg @@ -0,0 +1,190 @@ + + + + + + + + + + + + + + + + +
+
+
+ ʼ +
+
+
+
+ + ʼ + +
+
+ + + + + + + + + + + +
+
+
+ ѯͼ +
+
+
+
+ + ѯͼ + +
+
+ + + + + + + + + + + + + + + + +
+
+
+ for i = 0 to num_partsʼѯ +
+
+
+
+ + for i = 0 to num_partsʼѯ + +
+
+ + + + + + + + + + + +
+
+
+ ѯѯͼ +
+
+
+
+ + ѯѯͼ + +
+
+ + + + +
+
+
+ Y +
+
+
+
+ + Y + +
+
+ + + + + + +
+
+
+ δѯѯͼ +
+
+
+
+ + δѯѯͼ + +
+
+ + + + +
+
+
+ N +
+
+
+
+ + N + +
+
+ + + + + + +
+
+
+ ͼ +
+
+
+
+ + ͼ + +
+
+
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file diff --git a/picture/read_data.drawio.svg b/picture/read_data.drawio.svg new file mode 100644 index 0000000..a815ac4 --- /dev/null +++ b/picture/read_data.drawio.svg @@ -0,0 +1,157 @@ + + + + + + + + + + + +
+
+
+ 输入图书id +
+
+
+
+ + 输入图书id + +
+
+ + + + + + +
+
+
+
+ + + 返回错误值 + + +
+
+
+
+
+ + 返回错误值 + +
+
+ + + + + + +
+
+
+ + 输出图书信息 +
+
+
+
+
+
+ + 输出图书信息 + +
+
+ + + + + + + + +
+
+
+ + 查看输入的图书ID是否和已有的图书相匹配 + +
+
+
+
+ + 查看输入的图书ID是否和已有的图书相匹配 + +
+
+ + + + +
+
+
+ 结束 +
+
+
+
+ + 结束 + +
+
+ + + + +
+
+
+ N +
+
+
+
+ + N + +
+
+ + + + +
+
+
+ Y +
+
+
+
+ + Y + +
+
+
+ + + + + Text is not SVG - cannot display + + + +
\ No newline at end of file