C語言實現(xiàn)銷售管理系統(tǒng)
更新時間:2022年02月28日 08:39:14 作者:淺夏&輕吟
這篇文章主要為大家詳細介紹了C語言實現(xiàn)銷售管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C語言實現(xiàn)銷售管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
這是題目,沒用到文件相關的函數(shù),所以不能保存在本地,每次讀入都得重新輸入。
#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("請錄入該銷售員每月的銷售額,輸入負數(shù)結束錄入\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("***********************************************銷售員管理系統(tǒng)***********************************************\n\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1.錄入銷售員信息\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2.展示所有銷售員的信息\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3.查找指定銷售員的指定月份的銷售額\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 4.修改指定銷售員指定月份的銷售額\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 5.刪除指定員工的信息\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 6.統(tǒng)計所有員工的年度銷售總量\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 7.統(tǒng)計最大和最小月銷售額和年銷售額\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(); }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
通過先序遍歷和中序遍歷后的序列還原二叉樹(實現(xiàn)方法)
下面小編就為大家?guī)硪黄ㄟ^先序遍歷和中序遍歷后的序列還原二叉樹(實現(xiàn)方法)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06