C語(yǔ)言實(shí)現(xiàn)銷售管理系統(tǒng)
本文實(shí)例為大家分享了C語(yǔ)言實(shí)現(xiàn)銷售管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
這是題目,沒用到文件相關(guān)的函數(shù),所以不能保存在本地,每次讀入都得重新輸入。
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<Windows.h> #include<conio.h> struct node { ?? ?char no[12]; ?/*代號(hào)*/ ?? ?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("請(qǐng)錄入銷售員的信息,輸入#退出\n"); ?? ?while (true) ?? ?{ ?? ??? ?node t; ?? ??? ?printf("------------------------\n"); ?? ??? ?printf("輸入第%d個(gè)銷售員的代號(hào):", list->size + 1); ?? ??? ?scanf("%s", t.no); ?? ??? ?if (strcmp(t.no, "#") == 0) ?? ??? ??? ?break; ?? ??? ?if (hasExist(list, t.no)) ?? ??? ?{ ?? ??? ??? ?printf("該代號(hào)已存在!\n"); ?? ??? ??? ?continue; ?? ??? ?} ?? ??? ?printf("請(qǐng)輸入第%d個(gè)銷售員的姓名:", list->size + 1); ?? ??? ?scanf("%s", t.name); ?? ??? ?memset(t.sales, 0, sizeof(t.sales)); ?? ??? ?printf("請(qǐng)錄入該銷售員每月的銷售額,輸入負(fù)數(shù)結(jié)束錄入\n"); ?? ??? ?for (int i = 0; i < 12; i++) ?? ??? ?{ ?? ??? ??? ?printf("請(qǐng)輸入該銷售員%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個(gè)銷售員\n", index); ?? ??? ?printf("代號(hào):%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("請(qǐng)按下任意鍵返回"); ?? ?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)計(jì)所有員工的年度銷售總量\n"); ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 7.統(tǒng)計(jì)最大和最小月銷售額和年銷售額\n\n"); ?? ?printf("****************************************************************************************************************\n"); } void search(List* list) { ?? ?printf("按1通過(guò)代號(hào)查找,否則通過(guò)姓名查找\n"); ?? ?if (getch() == '1') ?? ?{ ?? ??? ?printf("請(qǐng)輸入代號(hào):"); ?? ??? ?char s[12]; ?? ??? ?scanf("%s", s); ?? ??? ?printf("請(qǐng)輸入要查找的月份:"); ?? ??? ?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("請(qǐng)按任意鍵返回"); ?? ??? ?getch(); ?? ?} ?? ?else ?? ?{ ?? ??? ?printf("請(qǐng)輸入姓名:"); ?? ??? ?char s[40]; ?? ??? ?scanf("%s", s); ?? ??? ?printf("請(qǐng)輸入要查找的月份:"); ?? ??? ?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("請(qǐng)按任意鍵返回"); ?? ??? ?getch(); ?? ?} } void change(List* list) { ?? ?printf("請(qǐng)輸入待修改員工的代號(hào):"); ?? ?char s[12]; ?? ?scanf("%s", s); ?? ?while (!hasExist(list, s)) ?? ?{ ?? ??? ?printf("該員工不存在,請(qǐng)重新輸入!或輸入#退出\n"); ?? ??? ?scanf("%s", s); ?? ??? ?if (strcmp("#", s) == 0) ?? ??? ??? ?return; ?? ?} ?? ?printf("請(qǐng)輸入待修改的月份:"); ?? ?int month; ?? ?scanf("%d", &month); ?? ?printf("請(qǐng)輸入修改后的銷售額:"); ?? ?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("代號(hào):%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("請(qǐng)按任意鍵返回"); ?? ?getch(); } void deleteInfo(List* list) { ?? ?printf("請(qǐng)輸入待刪除員工的代號(hào):"); ?? ?char s[12]; ?? ?scanf("%s", s); ?? ?while (!hasExist(list, s)) ?? ?{ ?? ??? ?printf("該員工不存在,請(qǐng)重新輸入或輸入#退出\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("代號(hào):%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("請(qǐng)按'1'確認(rèn)刪除,其余鍵返回主菜單\n"); ?? ?if (getch() == '1') ?? ?{ ?? ??? ?if (pro == ptr) ?? ??? ?{ ?? ??? ??? ?list->head = list->end = NULL; ?? ??? ??? ?free(ptr); ?? ??? ??? ?printf("刪除成功!\n請(qǐng)按任意鍵返回"); ?? ??? ??? ?getch(); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?pro->link = ptr->link; ?? ??? ??? ?free(ptr); ?? ??? ??? ?printf("刪除成功!\n請(qǐng)按任意鍵返回"); ?? ??? ??? ?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("請(qǐng)按任意鍵返回\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 代號(hào):%s\n", maxMonth, maxNo); ?? ?printf("最小月銷售額:%.2f 代號(hào):%s\n", minMonth, minNo); ?? ?printf("最大年銷售總額:%.2f 代號(hào):%s\n", maxYear, maxYearNo); ?? ?printf("最小年銷售總額:%.2f 代號(hào):%s\n", minYear, minYearNo); ?? ?printf("-------------------------------------"); ?? ?getch(); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++實(shí)現(xiàn)公司人事管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)公司人事管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03C語(yǔ)言多線程開發(fā)中死鎖與讀寫鎖問(wèn)題詳解
死鎖是指多個(gè)線程因競(jìng)爭(zhēng)資源而造成的僵局(互相等待);有些公共數(shù)據(jù)修改的機(jī)會(huì)很少,但其讀的機(jī)會(huì)很多。并且在讀的過(guò)程中會(huì)伴隨著查找,給這種代碼加鎖會(huì)降低我們的程序效率。讀寫鎖可以解決這個(gè)問(wèn)題;2022-05-05通過(guò)先序遍歷和中序遍歷后的序列還原二叉樹(實(shí)現(xiàn)方法)
下面小編就為大家?guī)?lái)一篇通過(guò)先序遍歷和中序遍歷后的序列還原二叉樹(實(shí)現(xiàn)方法)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06C語(yǔ)言詳解Z字形變換排列的實(shí)現(xiàn)
Z字形變換排列就是指將一個(gè)給定字符串根據(jù)給定的行數(shù),以從上往下、從左到右進(jìn)行 Z 字形排列,下面讓我們用C語(yǔ)言來(lái)實(shí)現(xiàn)2022-04-04