diff --git a/code/sell.cpp b/code/sell.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce6c83d7359d482e9c1f1bfc3605357544e195b1 --- /dev/null +++ b/code/sell.cpp @@ -0,0 +1,275 @@ +#include +#include +#include +#include +#include "sellFun.h" + +extern commodity commodity_head;//商品(库存)头指针 + +__declspec(selectany) records *all;//总销售记录头指针 +records *single;//实时销售记录头指针 +bool isAllInited = false;//总销售记录头指针是否已被初始化 + +/**************************************************** + * createRecordList -- 创建记录链表 + * 参数:无 + * 返回值:记录链表头指针 + ****************************************************/ +records *createRecordList() +{ + records *recordHead; + recordHead = (records *)malloc(sizeof(records)); + recordHead->next = NULL; + return recordHead; +} + +/**************************************************** + * searchGoods -- 货物是否存在(货查) + * 参数:id:商品编号 + * head:货物头指针 + * 返回值:若找到,返回指向该商品的指针,否则返回NULL + ****************************************************/ +goods *searchGoods(char *id, goods *head) +{ + goods *p; + p = head->next; + while(p != NULL) + { + if(strcmp(id, p->id_Number) == 0) + { + return p; + } + p = p->next; + } + return NULL; +} + +/**************************************************** + * addRecords -- 增加销售记录 + * 参数:record:销售记录头指针 + * soldGoods:卖的货结构体(售货信息) + * goods:商品信息 + * salespersonName:售货员姓名 + * lt:当前时间 + * 返回值:无 + ****************************************************/ +void addRecords(records *record, soldGoods soldGoods, goods *goods, char salespersonName[], struct tm *lt) +{ + records *p; + p = (records *)malloc(sizeof(records)); + strcpy(p->id, goods->id_Number); //货物编号 + strcpy(p->goodsName, goods->goods_Name); //货名 + p->count = soldGoods.count; //数量 + strcpy(p->people, salespersonName); //销售员姓名 + p->price = soldGoods.count * goods->sell_Price; //售价 + p->year = lt->tm_year + 1900; //年 + p->mon = lt->tm_mon + 1; //月 + p->day = lt->tm_mday; //日 + p->hour = lt->tm_hour; //时 + p->min = lt->tm_min; //分 + p->sec = lt->tm_sec; //秒 + p->next = NULL; + p->next = record->next; + record->next = p; +} + +/**************************************************** + * searchSingleRecord -- 查找实时记录 + * 参数:head:实时记录头指针 + * id:货物id + * 返回值:查找到则返回该项指针,否则返回NULL + ****************************************************/ +records *searchSingleRecord(records *head, char *id) +{ + records *p; + p = head->next; + while(p != NULL) + { + if(strcmp(id, p->id) == 0) + { + return p; + } + p = p->next; + } + return NULL; +} + +/**************************************************** + * searchAllRecord -- 查找总记录 + * 参数:head:总记录头指针 + * name:货物名 + * 返回值:查找到则返回该项指针,否则返回NULL + ****************************************************/ +records *searchAllRecord(records *head, char *name) +{ + records *p; + p = head->next; + while(p != NULL) + { + if(strcmp(name, p->goodsName) == 0) + { + return p; + } + p = p->next; + } + return NULL; +} + +/**************************************************** + * printSingleRecord -- 打印实时记录 + * 参数:head:实时记录链表头指针 + * 返回值:无 + ****************************************************/ +void printSingleRecord(records *head) +{ + records *p; + p = head->next; + if(p != NULL) + { + printf("商品编号 商品名 卖货人 销售额 销售时间\n"); + while(p != NULL) + { + printf("%s %s %s %.2lf %d年%d月%d日 %d:%d:%d\n", p->id, p->goodsName, p->people, p->price, p->year, p->mon, p->day, p->hour, p->min, p->sec); + p = p->next; + } + } + else + { + printf("实时销售记录为空!\n"); + } +} + +/**************************************************** + * printAllRecord -- 打印总记录 + * 参数:head:总记录链表头指针 + * 返回值:无 + ****************************************************/ +void printAllRecord(records *head) +{ + records *p; + p = head->next; + if(p != NULL) + { + printf("商品名 销售额 销售时间\n"); + while(p != NULL) + { + printf("%s %.2lf %d年%d月%d日 %d:%d:%d\n", p->goodsName, p->price, p->year, p->mon, p->day, p->hour, p->min, p->sec); + p = p->next; + } + } + else + { + printf("总销售记录为空!\n"); + } +} + +/**************************************************** + * sell -- 卖货,返回实时销售记录(货删和改,记录增) + * 参数:goodsHead:库存链表头指针 + * singleRecord:实时销售记录头指针 + * a:顾客所买东西的种类数(的引用) + * 返回值:当前该件商品的小计金额 + ****************************************************/ +double sell(goods *goodsHead, records *singleRecord, int &a) +{ + soldGoods soldGoods; + double money; + char salespersonName[15]; + printf("请依次输入销售员姓名 商品编号 购买数量:\n"); + scanf("%s %s %d", salespersonName, soldGoods.id_Number, &soldGoods.count); + goods *n = searchGoods(soldGoods.id_Number, goodsHead); + if(n != NULL) + { + if(soldGoods.count > n->remain_Number) + { + printf("库存不足,请重新清点商品数量!\n"); + a = a + 1; //重新计数 + return 0; + } + n->remain_Number = n->remain_Number - soldGoods.count; //更新库存 + if(n->remain_Number == 0) + { + printf("%s(%s)正好卖没货了。\n", n->goods_Name, n->id_Number); //可以删除但还是要进货的 + } + time_t t; + struct tm *lt; + time(&t); + lt = localtime(&t); //获取当前时间 + addRecords(singleRecord, soldGoods, n, salespersonName, lt); //更新实时销售记录 + addRecords(all, soldGoods, n, salespersonName, lt); // 更新总销售记录 + return soldGoods.count * n->sell_Price; + } + else + { + printf("未找到编号为 %s 的商品,请重新输入!\n", soldGoods.id_Number); + a = a + 1; //重新计数 + return 0; + } +} + +/**************************************************** + * sellmain -- 销售管理主界面 + * 参数:无 + * 返回值:正确结束,返回0 + ****************************************************/ +int sellmain() +{ + goods *goods = commodity_head;//货物头指针 + double money1 = 0, money2 = 0, money3 = 0; + int n; + int a; + single = createRecordList(); + if(!isAllInited) + { + all = createRecordList(); + isAllInited = true; + } + while(1) + { + system("cls"); + printf("顾客结账请按 1\n"); + printf("打印实时销售记录请按 2\n"); + printf("打印总销售记录 3\n"); + printf("退出程序请按 0\n"); + printf("\n请选择:"); + scanf("%d", &a); + if(a == 1) + { + printf("输入顾客所买东西的种类数:"); + scanf("%d", &n); + printf("开始结账(请手动输入):\n"); + while(n > 0) + { + money2 = money2 + sell(goods, single, n); + n--; + } + printf("金额合计:%.2lf元。\n", money2); + printf("输入顾客所付钱数:"); + scanf("%lf", &money1); + if(money1 >= money2) + printf("找零:%.2f元。\n", money1 - money2); + else + { + printf("所付金额不足,请继续付款:"); + scanf("%lf", &money3); + money1 = money1 + money3; + printf("找零:%.2f元。\n", money1 - money2); + } + } + else if(a == 2) + { + printSingleRecord(single); + } + else if(a == 3) + { + printAllRecord(all); + } + else if(a == 0) + { + break; + } + system("pause"); + } + + return 0; +} \ No newline at end of file diff --git a/code/sell.h b/code/sell.h new file mode 100644 index 0000000000000000000000000000000000000000..186a8956861402a93835c5e78c833564aa911826 --- /dev/null +++ b/code/sell.h @@ -0,0 +1,49 @@ +#ifndef __SELL_H__ +#define __SELL_H__ + +#include "date.h" + +//库存商品结构体 +typedef struct goods +{ + char id_Number[20]; // 商品编号 + char goods_Name[20]; // 商品名称 + char place[20]; // 库存位置 + double buy_Price; // 商品进价 + double sell_Price; // 商品售价 + int remain_Number; // 商品数量 + int quality_Date; // 保质期 + date purchase_Date; // 进货日期 + date produce_Date; // 生产日期 + goods *pre; // 上一个商品指针 + goods *next; // 下一个商品指针 +}*commodity; + +//卖的货结构体 +struct soldGoods +{ + char id_Number[20];//商品编号 + char name[20]; + int count;//数量 + double price;//单价 +}; + +//销售记录结构体 +struct records +{ + char id[20];//货物id + char goodsName[20];//货物名 + char people[20];//销售员 + int count;//销售数量 + double price;//销售金额 + //销售时间 + int year; + int mon; + int day; + int hour; + int min; + int sec; + records *next; +}; + +#endif // !__SELL_H__ diff --git a/code/sellFun.h b/code/sellFun.h new file mode 100644 index 0000000000000000000000000000000000000000..7f3c1587bb9b238aa9cd019ef0c4326027f73a30 --- /dev/null +++ b/code/sellFun.h @@ -0,0 +1,33 @@ +#ifndef __SELLFUN_H__ +#define __SELLFUN_H__ + +#include "sell.h" + +//创建记录链表 +records *createRecordList(); + +//货物是否存在(货查) +goods *searchGoods(char *id, goods *head); + +//增加销售记录 +void addRecords(records *record, soldGoods soldGoods, goods *goods, char salespersonName[], struct tm *lt); + +//查找实时记录 +records *searchSingleRecord(records *head, char *id); + +//查找总记录 +records *searchAllRecord(records *head, char *name); + +//打印实时记录 +void printSingleRecord(records *head); + +//打印总记录 +void printAllRecord(records *head); + +//卖货,返回实时销售记录(货删和改,记录增) +double sell(goods *goodsHead, records *singleRecord, int &a); + +//销售管理主界面 +int sellmain(); + +#endif // !__SELLFUN_H__