C语言实现销售管理系统
本文实例为大家分享了C语言实现销售管理系统的具体代码,供大家参考,具体内容如下
这是题目,没用到文件相关的函数,所以不能保存在本地,每次读入都得重新输入。
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<Windows.h> #include<conio.h> struct node { char no[12]; /*代号*/ char name[40]; /*姓名*/ float sales[12]; /*月销售额*/ float total; /*年度总销售额*/ struct node* link; }; struct List { node* head; node* end; int size; }; List* init(); void pushNode(List* list); bool hasExist(List* list, char* no); void addNode(List* list, node t); void showNodes(List* list); void mainMenu(); void search(List* list); void change(List* list); void deleteInfo(List* list); void showTotal(List* list); void findMaxMin(List* list); int main() { List* list = init(); mainMenu(); while (true) { char c; c = getch(); if (c == '1') pushNode(list); if (c == '2') showNodes(list); if (c == '3') search(list); if (c == '4') change(list); if (c == '5') deleteInfo(list); if (c == '6') showTotal(list); if (c == '7') findMaxMin(list); mainMenu(); } return 0; } List* init() { List* list = (List*)malloc(sizeof(List)); list->head = list->end = NULL; list->size = 0; return list; } void pushNode(List* list) { node t; printf("请录入销售员的信息,输入#退出\n"); while (true) { node t; printf("------------------------\n"); printf("输入第%d个销售员的代号:", list->size + 1); scanf("%s", t.no); if (strcmp(t.no, "#") == 0) break; if (hasExist(list, t.no)) { printf("该代号已存在!\n"); continue; } printf("请输入第%d个销售员的姓名:", list->size + 1); scanf("%s", t.name); memset(t.sales, 0, sizeof(t.sales)); printf("请录入该销售员每月的销售额,输入负数结束录入\n"); for (int i = 0; i < 12; i++) { printf("请输入该销售员%d月的销售额:", i + 1); float temp; scanf("%f", &temp); if (temp < 0) break; else t.sales[i] = temp; } t.total = 0; for (int i = 0; i < 12; i++) t.total += t.sales[i]; t.link = NULL; addNode(list, t); } } bool hasExist(List* list, char* no) { node* ptr = list->head; while (ptr != NULL) { if (strcmp(ptr->no, no) == 0) return true; ptr = ptr->link; } return false; } void addNode(List* list, node t) { node* nd = (node*)malloc(sizeof(node)); strcpy(nd->no, t.no); strcpy(nd->name, t.name); nd->link = t.link; for (int i = 0; i < 12; i++) nd->sales[i] = t.sales[i]; nd->total = t.total; if (list->head == NULL) list->head = list->end = nd; else { list->end->link = nd; list->end = nd; } list->size++; } void showNodes(List* list) { node* ptr = list->head; int index = 1; while (ptr != NULL) { if (index != 1) printf("------------------\n"); printf("第%d个销售员\n", index); printf("代号:%s\n", ptr->no); printf("姓名:%s\n", ptr->name); for (int i = 0; i < 12; i++) if (ptr->sales[i] != 0) printf("%d月销售额:%.2f\n", i + 1, ptr->sales[i]); printf("总销售额:%.2f\n", ptr->total); index++; ptr = ptr->link; } printf("---------------\n"); printf("请按下任意键返回"); getch(); } void mainMenu() { system("cls"); printf("***********************************************销售员管理系统***********************************************\n\n"); printf(" 1.录入销售员信息\n"); printf(" 2.展示所有销售员的信息\n"); printf(" 3.查找指定销售员的指定月份的销售额\n"); printf(" 4.修改指定销售员指定月份的销售额\n"); printf(" 5.删除指定员工的信息\n"); printf(" 6.统计所有员工的年度销售总量\n"); printf(" 7.统计最大和最小月销售额和年销售额\n\n"); printf("****************************************************************************************************************\n"); } void search(List* list) { printf("按1通过代号查找,否则通过姓名查找\n"); if (getch() == '1') { printf("请输入代号:"); char s[12]; scanf("%s", s); printf("请输入要查找的月份:"); int month; scanf("%d", &month); node* ptr = list->head; bool flag = false; while (ptr != NULL) { if (strcmp(ptr->no, s) == 0) { flag = true; break; } ptr = ptr->link; } if (flag) printf("销售额为:%.2f\n", ptr->sales[month - 1]); else printf("暂未录入此销售员信息!\n"); printf("请按任意键返回"); getch(); } else { printf("请输入姓名:"); char s[40]; scanf("%s", s); printf("请输入要查找的月份:"); int month; scanf("%d", &month); node* ptr = list->head; bool flag = false; while (ptr != NULL) { if (strcmp(ptr->name, s) == 0) { flag = true; break; } ptr = ptr->link; } if (flag) printf("销售额为:%.2f\n", ptr->sales[month - 1]); else printf("暂未录入此销售员信息!\n"); printf("请按任意键返回"); getch(); } } void change(List* list) { printf("请输入待修改员工的代号:"); char s[12]; scanf("%s", s); while (!hasExist(list, s)) { printf("该员工不存在,请重新输入!或输入#退出\n"); scanf("%s", s); if (strcmp("#", s) == 0) return; } printf("请输入待修改的月份:"); int month; scanf("%d", &month); printf("请输入修改后的销售额:"); float temp; scanf("%f", &temp); node* ptr = list->head; while (ptr != NULL) if (strcmp(ptr->no, s) == 0) break; ptr->sales[month - 1] = temp; ptr->total = 0; for (int i = 0; i < 12; i++) ptr->total += ptr->sales[i]; printf("修改成功!\n"); printf("------------------\n"); printf("代号:%s\n", ptr->no); printf("姓名:%s\n", ptr->name); for (int i = 0; i < 12; i++) if (ptr->sales[i] != 0) printf("%d月销售额:%.2f\n", i + 1, ptr->sales[i]); printf("总销售额:%.2f\n", ptr->total); printf("--------------------\n"); printf("请按任意键返回"); getch(); } void deleteInfo(List* list) { printf("请输入待删除员工的代号:"); char s[12]; scanf("%s", s); while (!hasExist(list, s)) { printf("该员工不存在,请重新输入或输入#退出\n"); scanf("%s", s); if (strcmp("#", s) == 0) return; } node* pro = list->head; node* ptr; if (strcmp(pro->no, s) == 0) { ptr = pro; } else { while (pro != NULL) { if (strcmp(pro->link->no, s) == 0) break; pro = pro->link; } node* ptr = pro->link; } printf("------该员工信息-------\n"); printf("代号:%s\n", ptr->no); printf("姓名:%s\n", ptr->name); for (int i = 0; i < 12; i++) if (ptr->sales[i] != 0) printf("%d月销售额:%.2f\n", i + 1, ptr->sales[i]); printf("总销售额:%.2f\n", ptr->total); printf("----------------------\n"); printf("请按'1'确认删除,其余键返回主菜单\n"); if (getch() == '1') { if (pro == ptr) { list->head = list->end = NULL; free(ptr); printf("删除成功!\n请按任意键返回"); getch(); } else { pro->link = ptr->link; free(ptr); printf("删除成功!\n请按任意键返回"); getch(); } } else return; } void showTotal(List* list) { float tal = 0; node* ptr = list->head; while (ptr != NULL) { tal += ptr->total; ptr = ptr->link; } printf("------------------\n"); printf("总销售额为%.2f\n", tal); printf("-------------------\n"); printf("请按任意键返回\n"); getch(); } void findMaxMin(List* list) { float maxMonth, minMonth; char* maxNo, *minNo; float maxYear, minYear; char* maxYearNo, *minYearNo; node* ptr = list->head; if (ptr != NULL) { minMonth = maxMonth = ptr->sales[0]; maxNo = minNo = ptr->no; maxYear = minYear = ptr->total; maxYearNo = minYearNo = ptr->no; } else return; while (ptr != NULL) { for (int i = 0; i < 12; i++) { if (minMonth > ptr->sales[i]) { minMonth = ptr->sales[i]; minNo = ptr->no; } if (maxMonth < ptr->sales[i]) { maxMonth = ptr->sales[i]; maxNo = ptr->no; } } if (maxYear < ptr->total) { maxYear = ptr->total; maxYearNo = ptr->no; } if (minYear > ptr->total) { minYear = ptr->total; minYearNo = ptr->no; } ptr = ptr->link; } printf("-------------------------------------"); printf("最大月销售额:%.2f 代号:%s\n", maxMonth, maxNo); printf("最小月销售额:%.2f 代号:%s\n", minMonth, minNo); printf("最大年销售总额:%.2f 代号:%s\n", maxYear, maxYearNo); printf("最小年销售总额:%.2f 代号:%s\n", minYear, minYearNo); printf("-------------------------------------"); getch(); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)