药店管理系统

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

药店药品管理系统旨在通过面向对象程序设计实现药品信息管理、库存动态监控、进货销售记录、过期预警及销售统计等功能。

一、设计需求概述

系统需满足以下核心需求:

  1. 角色划分:员工与管理员权限分离。
    员工功能:药品进货、销售、库存查询、销售记录统计(日/月/季/年/类别)。
    管理员功能:药品信息增删改、系统数据维护。
  2. 核心模块:
    库存管理:实时更新库存量,当库存低于阈值(MIN=10)时自动预警。
    保质期监控:自动检测过期药品并提示清理。
    文件持久化:药品信息、进货记录、销售记录通过文件存储。
    数据统计:支持按日、月、季度、年及药品类别统计销售额。

二、系统总体设计

1.系统功能设计

功能模块 描述
药品管理 管理员可添加、删除、修改药品信息(名称、编码、类别、价格)。
进货管理 员工录入进货信息(数量、生产日期、保质期),更新库存并记录入库时间。
销售管理 员工登记销售信息(数量、出库时间),更新库存并记录销售时间。
查询功能 按药品编码或名称查询信息,支持查看进货记录、销售记录及药品目录。
库存预警 自动检测低库存药品并提示;定期扫描过期药品,需手动清理。
销售统计 按时间维度(日/月/季/年)或药品类别统计总销售额。

2.数据模型设计

1.类结构设计

  1. Date结构体:
    属性: int year(年); int month(月); int day(日);
    功能:用于记录药品的生产日期、保质期、入库时间等。
  2. Goods结构体:
    属性:Date production_date(生产日期)、Date date_of_use(保质期)、Date inventory_time(入库时间)、Date selling_time(销售时间)、Date in_number(进货数量)、Date out_number(销售数量)。
    功能:记录药品的进货和销售信息。
  3. Drug类:
    属性:
    string name(药品名称)、int code(药品编码)、string category(药品类别)、double prices(药品价格)。
    成员函数:
    Void ShowDrug():显示药品信息。
  4. Warehouse类(继承自Drug类):
    属性:
    Goods good(药品进货和销售信息)、int stockpile(库存数量)。
    成员函数:
    void ShowInGoods():显示进货记录。
    void ShowOutGoods():显示销售记录。
  5. DrugManagement类:
    属性:
    Warehouse** drug_arry(药品数组)、Warehouse** shipping_arry(进货和销售记录数组)、int number_drug(药品数量)、int number_in_goods(进货记录数量)、int number_out_goods(销售记录数量)。
    成员函数:
    药品管理:void AddDrug(),void DeleteDrug(),void ModifyDrug()
    库存管理:void AutomaticWarningStockpile(),void AutomaticWarningDate()
    进货与销售:void Shipping(),void Receiving()
    数据统计:void StatisticDay(),void StatisticMonth(),void StatisticQuarter(),void StatisticYear(),void StatisticCategory()
    文件操作:void SaveFile(),void LoadFile(),void SaveShippingFile(),void LoadShippingFile()

2类的实现

DrugManagement.h

#pragma once
#include <iostream>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <chrono>
#include <string>
using namespace std;

#define file_drug "drug.txt"
#define file_shipping "shipping.txt"
#define file_receiving "receiving.txt"
#define MIN 10

struct Date {
	int year;
	int month;
	int day;
};
struct Goods {
	Date production_date;
	Date date_of_use;
	Date inventory_time;
	Date selling_time;
	int in_number;
	int out_number;
};
class Drug {
private:
	
public:
	Drug(string name, int code, string category, double prices);
	void ShowDrug();
	~Drug();
	string name;
	int code;
	string name1;
	int code1;
	string category;
	double prices;
};
class Warehouse : public Drug{
public:
	Warehouse(string name, int code, string category, double prices);
	Warehouse(string name);
	void ShowInGoods();
	void ShowOutGoods();
	~Warehouse();
	Goods good;
	int stockpile = 0;
};
class DrugManagement {
private:
	int number_in_goods;
	int number_out_goods;
	int number_goods;
	Warehouse** shipping_arry;
	int number_drug;
	Warehouse** drug_arry;
	bool file_is_empty;
public:
	DrugManagement();
	//系统
	void ExitSystem();
	void AutomaticWarningStockpile();
	void AutomaticWarningDate();
	void Cleaning(int index);
	//界面
	void ShowMenu00();
	void ShowMenu01();
	void ShowMenu02();
	void ShowMenu03();
	void ShowMenu04();
	void ShowMenu05();
	//增删改
	void AddDrug();
	void DeleteDrug();
	void ModifyDrug();
	void SaveFile();
	int GetNumber();
	void LoadFile();
	//进货
	void Shipping();
	void SaveShippingFile();
	int GetShippingNumber();
	void LoadShippingFile();
	//出货
	void Receiving();
	void SaveReceivingFile();
	int GetReceivingNumber();
	void LoadReceivingFile();
	//查询
	int IsDrug(int code);
	int IsName(string name);
	void FindDrug();
	void ShowShipping();
	void ShowReceiving();
	void ShowDrug();
	//统计
	void StatisticDay();
	void StatisticMonth();
	void StatisticQuarter();
	void StatisticYear();
	void StatisticCategory();
	~DrugManagement();
};



DrugManagement.cpp

#include "DrugManagement.h"
void PrintDate(const Date& date) {
    cout << date.year << "-" << date.month << "-" << date.day;
}

DrugManagement::DrugManagement() {
    ifstream ifs;
    ifs.open(file_drug, ios::in);
    if (!ifs.is_open()) {
        cout << "目前无药品" << endl;
        this->number_drug = 0;
        this->drug_arry = NULL;
        this->number_in_goods = 0;
        this->shipping_arry = NULL;
        this->file_is_empty = true;
        ifs.close();
        return;
    }
    char first;
    ifs >> first;
    if (ifs.eof()) {
        cout << "目前无药品" << endl;
        this->number_drug = 0;
        this->drug_arry = NULL;
        this->number_in_goods = 0;
        this->shipping_arry = NULL;
        this->file_is_empty = true;
        ifs.close();
        return;
    }
    this->number_drug = this->GetNumber();
    this->drug_arry = new Warehouse * [this->number_drug];
    LoadFile();

    this->number_in_goods = this->GetShippingNumber();
    this->number_out_goods = this->GetReceivingNumber();
    this->number_goods = max(this->number_in_goods, this->number_out_goods);
    this->shipping_arry = new Warehouse * [this->number_goods];
    for (int i = 0; i < this->number_goods + 10; ++i) {
        this->shipping_arry[i] = new Warehouse(" ");
    }

    LoadShippingFile();
    LoadReceivingFile();

    for (int i = 0; i < this->number_in_goods; ++i) {
        int index = this->IsDrug(this->shipping_arry[i]->code);
        this->drug_arry[index]->stockpile += this->shipping_arry[i]->good.in_number;
    }
    for (int i = 0; i < this->number_out_goods; ++i) {
        int index = this->IsDrug(this->shipping_arry[i]->code1);
        this->drug_arry[index]->stockpile -= this->shipping_arry[i]->good.out_number;
    }
}
void DrugManagement::ExitSystem() {
    cout << "欢迎下次使用!" << endl;
    system("pause");
    exit(0);
}
void DrugManagement::AutomaticWarningStockpile() {
    for (int i = 0; i < this->number_drug; ++i) {
        if (this->drug_arry[i]->stockpile <= MIN) {
            cout << this->drug_arry[i]->name  << this->drug_arry[i]->code << "的库存为:" << this->drug_arry[i]->stockpile
                << ",请注意及时补充!" << endl;
        }
    }
}
void DrugManagement::AutomaticWarningDate() {
    auto now = chrono::system_clock::now();
    auto in_time_t = chrono::system_clock::to_time_t(now);
    tm buf;
    localtime_s(&buf, &in_time_t);

    Date date;
    date.year = buf.tm_year + 1900;
    date.month = buf.tm_mon + 1;
    date.day = buf.tm_mday;

    for (int i = 0; i < this->number_in_goods; ++i) {
        if (this->shipping_arry[i]->good.date_of_use.year <= date.year &&
            this->shipping_arry[i]->good.date_of_use.month <= date.month &&
            this->shipping_arry[i]->good.date_of_use.day < date.day) {
            cout << "第" << i + 1 << "次进货的药品" << this->shipping_arry[i]->name << this->shipping_arry[i]->code 
                << "已过保质期(";
            PrintDate(this->shipping_arry[i]->good.date_of_use);
            cout << "),请注意及时清理(输入“ 清理 ”二字)!" << endl;
            string s;
            cin >> s;
            if (s == "清理") {
                this->Cleaning(i);
            }
            else {
                cout << "输入“ 清理 ”二字!!!" << endl;
            }
        }
    }
}
void DrugManagement::Cleaning(int index) {
    int mark = this->IsDrug(this->shipping_arry[index]->code);
    this->drug_arry[mark]->stockpile -= this->shipping_arry[index]->good.in_number;

    for (int i = index; i < this->number_in_goods; ++i) {
        this->shipping_arry[i]->name = this->shipping_arry[i + 1]->name;
        this->shipping_arry[i]->code = this->shipping_arry[i + 1]->code;
        this->shipping_arry[i]->good.in_number = this->shipping_arry[i + 1]->good.in_number;
        this->shipping_arry[i]->good.production_date = this->shipping_arry[i + 1]->good.production_date;
        this->shipping_arry[i]->good.date_of_use = this->shipping_arry[i + 1]->good.date_of_use;
        this->shipping_arry[i]->good.inventory_time = this->shipping_arry[i + 1]->good.inventory_time;
    }
    this->number_in_goods--;
    this->SaveShippingFile();
    cout << "清理成功!" << endl;

}

void DrugManagement::ShowMenu00() {
    cout << "---------------------------------------------------" << endl;
    cout << "------------欢迎使用药店药品管理系统!--------------" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "-----------------1.员工-------------------" << endl;
    cout << "-----------------2.管理员-----------------" << endl;
    cout << "请根据您的身份选择对应的序号!!!" << endl;
    cout << "请输入您的选择: ";
}
void DrugManagement::ShowMenu01() {
    cout << "---------------------------------------------------" << endl;
    cout << "------------欢迎使用药店药品管理系统!--------------" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "请输入管理员密码: " << endl;
}
void DrugManagement::ShowMenu02() {
    cout << "---------------------------------------------------" << endl;
    cout << "------------欢迎使用药店药品管理系统!--------------" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "-----------------1.增加药品-------------------" << endl;
    cout << "-----------------2.删除药品-------------------" << endl;
    cout << "-----------------3.修改药品-------------------" << endl;
    cout << "请根据您的需要选择对应的序号!!!" << endl;
    cout << "请输入您的选择: ";
}
void DrugManagement::ShowMenu03() {
    cout << "---------------------------------------------------" << endl;
    cout << "------------欢迎使用药店药品管理系统!--------------" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "-----------------1.进货入库-------------------" << endl;
    cout << "-----------------2.销售出库-------------------" << endl;
    cout << "-----------------3.查询信息-------------------" << endl;
    cout << "-----------------4.统计数据-------------------" << endl;
    cout << "请根据您的需要选择对应的序号!!!" << endl;
}
void DrugManagement::ShowMenu04() {
    cout << "---------------------------------------------------" << endl;
    cout << "------------欢迎使用查询信息功能!--------------" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "-----------------1.查询药品-------------------" << endl;
    cout << "-----------------2.进货记录-------------------" << endl;
    cout << "-----------------3.销售记录-------------------" << endl;
    cout << "-----------------4.药品目录-------------------" << endl;
    cout << "请根据您的需要选择对应的序号!!!" << endl;
    cout << "请输入您的选择: ";
}
void DrugManagement::ShowMenu05() {
    cout << "---------------------------------------------------" << endl;
    cout << "------------欢迎使用统计数据功能!--------------" << endl;
    cout << "---------------------------------------------------" << endl;
    cout << "-----------------1.日销售额-------------------" << endl;
    cout << "-----------------2.月销售额-------------------" << endl;
    cout << "-----------------3.季销售额-------------------" << endl;
    cout << "-----------------4.年销售额-------------------" << endl;
    cout << "-----------------5.类销售额-------------------" << endl;
    cout << "请根据您的需要选择对应的序号!!!" << endl;
    cout << "请输入您的选择: ";
}
void DrugManagement::AddDrug() {
    cout << "您要添加多少种药品" << endl;
    int AddNumber;
    cin >> AddNumber;
    if (AddNumber > 0) {
        int NewNumber = this->number_drug + AddNumber;
        Warehouse** NewArry = new Warehouse *[NewNumber];
        if (this->drug_arry != NULL) {
            for (int i = 0; i < this->number_drug; ++i) {
                NewArry[i] = this->drug_arry[i];
            }
        }
        for (int i = 0; i < AddNumber; ++i) {
            cout << "请输入第 " << (i + 1) << " 种药品的信息:" << endl;
            string name;
            int code;
            string category;
            double prices;

            cout << "药品名称:";
            cin >> name;
            code = 1001 + i + this->number_drug;
            cout << "药品类别:";
            cin >> category;
            cout << "药品价格:";
            cin >> prices;

            NewArry[this->number_drug + i] = new Warehouse(name, code, category, prices);
        }
        delete[] this->drug_arry;
        this->drug_arry = NewArry;
        this->number_drug = NewNumber;
        this->SaveFile();
    }
    else {
        cout << "输入数据有误,请重新输入!" << endl;

    }
}
void DrugManagement::DeleteDrug() {
    if (this->file_is_empty) {
        cout << "目前无药品" << endl;
    }
    else {
        cout << "请输入您想删除的药品编码:" << endl;
        int code;
        cin >> code;
        int index = this->IsDrug(code);
        if (index != -1) {
            for (int i = index; i < this->number_drug; ++i) {
                this->drug_arry[i] = this->drug_arry[i + 1];
            }
            this->number_drug--;
            for (int i = index; i < this->number_drug; ++i) {
                this->drug_arry[i]->code--;
            }
            this->SaveFile();
            cout << "删除成功!" << endl;
        }
        else {
            cout << "未找到该药品!" << endl;
        }
    }
    system("pause");
}
void DrugManagement::ModifyDrug() {
    if (this->file_is_empty) {
        cout << "目前无药品" << endl;
    }
    else {
        cout << "请输入您想修改的药品编码:" << endl;
        int code;
        cin >> code;
        int index = this->IsDrug(code);
        if (index != -1) {
            delete this->drug_arry[index];

            string name;
            string category;
            double prices;

            cout << "查找到药品编码为" << code << "的药品,请输入新的信息!" << endl;
            cout << "药品名称:";
            cin >> name;
            cout << "药品类别:";
            cin >> category;
            cout << "药品价格:";
            cin >> prices;

            Warehouse* Arry = new Warehouse(name, code, category, prices);
            this->drug_arry[index] = Arry;
            this->SaveFile();
            cout << "修改成功!" << endl;
        }
        else {
            cout << "未找到该药品!" << endl;
        }
    }
    system("pause");

}

void DrugManagement::SaveFile() {
    ofstream ofs;
    ofs.open(file_drug, ios::out);
    for (int i = 0; i < this->number_drug; ++i) {
        ofs << this->drug_arry[i]->name << " "
            << this->drug_arry[i]->code << " "
            << this->drug_arry[i]->category << " "
            << this->drug_arry[i]->prices << endl;
    }
    ofs.close();
}
int DrugManagement::GetNumber() {
    ifstream ifs;
    ifs.open(file_drug, ios::in);

    string name;
    int code;
    string category;
    double prices;

    int number = 0;

    while (ifs >> name >> code >> category
        >> prices) {
        number++;
    }

    ifs.close();

    return number;
}
void DrugManagement::LoadFile() {
    ifstream ifs;
    ifs.open(file_drug, ios::in);

    string name;
    int code;
    string category;
    double prices;

    int index = 0;

    while (ifs >> name >> code >> category
        >> prices) {
        drug_arry[index] = new Warehouse(name, code, category, prices);
        index++;
    }
}

void DrugManagement::Shipping() {
    if (this->file_is_empty) {
        cout << "目前无药品" << endl;
    }
    else {
        cout << "请输入您想进货的药品编码:" << endl;
        int code;
        cin >> code;
        int index = this->IsDrug(code);
        if (index != -1) {
            cout << "进货数量:" << endl;
            int number;
            cin >> number;
            if (number > 0) {
                this->shipping_arry[this->number_in_goods]->name = this->drug_arry[index]->name;
                this->shipping_arry[this->number_in_goods]->good.in_number = number;
                this->drug_arry[index]->stockpile += number;
                this->shipping_arry[this->number_in_goods]->code = code;
                cout << "请输入生产日期(格式:年 月 日):" << endl;
                cin >> this->shipping_arry[this->number_in_goods]->good.production_date.year
                    >> this->shipping_arry[this->number_in_goods]->good.production_date.month
                    >> this->shipping_arry[this->number_in_goods]->good.production_date.day;

                cout << "请输入保质期至(格式:年 月 日):" << endl;
                cin >> this->shipping_arry[this->number_in_goods]->good.date_of_use.year
                    >> this->shipping_arry[this->number_in_goods]->good.date_of_use.month
                    >> this->shipping_arry[this->number_in_goods]->good.date_of_use.day;

                auto now = chrono::system_clock::now();
                auto in_time_t = chrono::system_clock::to_time_t(now);
                tm buf;
                localtime_s(&buf, &in_time_t);
                this->shipping_arry[this->number_in_goods]->good.inventory_time.year = buf.tm_year + 1900;
                this->shipping_arry[this->number_in_goods]->good.inventory_time.month = buf.tm_mon + 1;
                this->shipping_arry[this->number_in_goods]->good.inventory_time.day = buf.tm_mday;

                this->number_in_goods++;
                this->SaveShippingFile();
                cout << "进货成功!" << endl;
            }
            else {
                cout << "进货数量必须是一个正数!" << endl;
            }
        }
        else {
            cout << "未找到该药品!" << endl;
        }
    }
}
void DrugManagement::SaveShippingFile() {
    ofstream ofs;
    ofs.open(file_shipping, ios::out);
    for (int i = 0; i < this->number_in_goods; ++i) {
        ofs << this->shipping_arry[i]->name << " "
            << this->shipping_arry[i]->code << " "
            << this->shipping_arry[i]->good.in_number << " "
            << this->shipping_arry[i]->good.production_date.year << " "
            << this->shipping_arry[i]->good.production_date.month << " "
            << this->shipping_arry[i]->good.production_date.day << " "
            << this->shipping_arry[i]->good.date_of_use.year << " "
            << this->shipping_arry[i]->good.date_of_use.month << " "
            << this->shipping_arry[i]->good.date_of_use.day << " "
            << this->shipping_arry[i]->good.inventory_time.year << " "
            << this->shipping_arry[i]->good.inventory_time.month << " "
            << this->shipping_arry[i]->good.inventory_time.day << endl;
    }
    ofs.close();
}
int DrugManagement::GetShippingNumber() {
    ifstream ifs;
    ifs.open(file_shipping, ios::in);

    string name;
    int code;
    Goods good;

    int number = 0;

    while (ifs >> name >> code >> good.in_number
        >> good.production_date.year >> good.production_date.month >> good.production_date.day
        >> good.date_of_use.year >> good.date_of_use.month >> good.date_of_use.day
        >> good.inventory_time.year >> good.inventory_time.month >> good.inventory_time.day) {
        number++;
    }

    ifs.close();
    return number;
}
void DrugManagement::LoadShippingFile() {
    ifstream ifs;
    ifs.open(file_shipping, ios::in);

    for (int i = 0; i < this->number_in_goods; ++i) {
        ifs >> this->shipping_arry[i]->name
            >> this->shipping_arry[i]->code
            >> this->shipping_arry[i]->good.in_number
            >> this->shipping_arry[i]->good.production_date.year
            >> this->shipping_arry[i]->good.production_date.month
            >> this->shipping_arry[i]->good.production_date.day
            >> this->shipping_arry[i]->good.date_of_use.year
            >> this->shipping_arry[i]->good.date_of_use.month
            >> this->shipping_arry[i]->good.date_of_use.day
            >> this->shipping_arry[i]->good.inventory_time.year
            >> this->shipping_arry[i]->good.inventory_time.month
            >> this->shipping_arry[i]->good.inventory_time.day;
    }
}
void DrugManagement::Receiving() {
    if (this->file_is_empty) {
        cout << "目前无药品" << endl;
        return;
    }

    cout << "请输入您要出售的药品编码:" << endl;
    int code;
    cin >> code;
    int index = this->IsDrug(code);
    if (index == -1) {
        cout << "未找到该药品!" << endl;
        return;
    }

    cout << "出售数量:" << endl;
    int number;
    cin >> number;

    if (number > this->drug_arry[index]->stockpile) {
        cout << "库存不足!" << endl;
        return;
    }
    this->shipping_arry[this->number_out_goods]->good.out_number = number;
    this->drug_arry[index]->stockpile -= number;
    this->shipping_arry[this->number_out_goods]->code1 = code;
    this->shipping_arry[this->number_out_goods]->name1 = this->drug_arry[index]->name;

    auto now = chrono::system_clock::now();
    auto in_time_t = chrono::system_clock::to_time_t(now);
    tm buf;
    localtime_s(&buf, &in_time_t);
    this->shipping_arry[this->number_out_goods]->good.selling_time.year = buf.tm_year + 1900;
    this->shipping_arry[this->number_out_goods]->good.selling_time.month = buf.tm_mon + 1;
    this->shipping_arry[this->number_out_goods]->good.selling_time.day = buf.tm_mday;


    this->number_out_goods++;
    cout << "出售成功!" << endl;

    this->SaveReceivingFile();
}
void DrugManagement::SaveReceivingFile() {
    ofstream ofs;
    ofs.open(file_receiving, ios::out);
    for (int i = 0; i < this->number_out_goods; ++i) {
        ofs << this->shipping_arry[i]->name1 << " "
            << this->shipping_arry[i]->code1 << " "
            << this->shipping_arry[i]->good.out_number << " "
            << this->shipping_arry[i]->good.selling_time.year << " "
            << this->shipping_arry[i]->good.selling_time.month << " "
            << this->shipping_arry[i]->good.selling_time.day << endl;
    }
    ofs.close();
}
int DrugManagement::GetReceivingNumber() {
    ifstream ifs;
    ifs.open(file_receiving, ios::in);

    string name;
    int code;
    Goods good;

    int number = 0;

    while (ifs >> name >> code >> good.out_number
        >> good.selling_time.year >> good.selling_time.month >> good.selling_time.day) {
        number++;
    }

    ifs.close();
    return number;
}
void DrugManagement::LoadReceivingFile() {
    ifstream ifs;
    ifs.open(file_receiving, ios::in);

    for (int i = 0; i < this->number_out_goods; ++i) {
        ifs >> this->shipping_arry[i]->name1
            >> this->shipping_arry[i]->code1
            >> this->shipping_arry[i]->good.out_number
            >> this->shipping_arry[i]->good.selling_time.year
            >> this->shipping_arry[i]->good.selling_time.month
            >> this->shipping_arry[i]->good.selling_time.day;
    }
}

int DrugManagement::IsDrug(int code) {
    int index = -1;
    for (int i = 0; i < this->number_drug; ++i) {
        if (this->drug_arry[i]->code == code) {
            index = i;
            break;
        }
    }
    return index;
}
int DrugManagement::IsName(string name) {
    int index = -1;
    for (int i = 0; i < this->number_drug; ++i) {
        if (this->drug_arry[i]->name == name) {
            index = i;
            break;
        }
    }
    return index;
}
void DrugManagement::FindDrug() {
    int choice;
    cout << "请选择查找方式:" << endl;
    cout << "1. 通过药品代码查找" << endl;
    cout << "2. 通过药品名称查找" << endl;
    cout << "请输入选择(1或2): ";
    cin >> choice;

    if (choice == 1) {
        int code;
        cout << "请输入药品代码: ";
        cin >> code;
        int index = IsDrug(code);
        if (index != -1) {
            cout << "药品找到!" << endl;
            cout << "药品名称: " << drug_arry[index]->name
                << " 药品编码: " << drug_arry[index]->code
                << " 药品类别: " << drug_arry[index]->category
                << " 药品价格: " << drug_arry[index]->prices << "元"
                << " 库存:" << this->drug_arry[index]->stockpile << endl;
        }
        else {
            cout << "未找到该药品。\n";
        }
    }
    else if (choice == 2) {
        string name;
        cout << "请输入药品名称: ";
        cin >> name;
        int index = IsName(name);
        if (index != -1) {
            cout << "药品找到!" << endl;
            cout << "药品名称: " << drug_arry[index]->name 
                << " 药品编码: " << drug_arry[index]->code 
                << " 药品类别: " << drug_arry[index]->category
                << " 药品价格: " << drug_arry[index]->prices << "元"
                << " 库存:" << this->drug_arry[index]->stockpile << endl;
        }
        else {
            cout << "未找到该药品。\n";
        }
    }
    else {
        cout << "输入错误,请重新选择。\n";
    }
}
void DrugManagement::ShowShipping() {
    for (int i = 0; i < this->number_in_goods; ++i) {
        this->shipping_arry[i]->ShowInGoods();
    }
    system("pause");
}
void DrugManagement::ShowReceiving() {
    for (int i = 0; i < this->number_out_goods; ++i) {
        this->shipping_arry[i]->ShowOutGoods();
    }
    system("pause");
}
void DrugManagement::ShowDrug() {
    if (this->file_is_empty) {
        cout << "目前无药品" << endl;
    }
    else {
        for (int i = 0; i < this->number_drug; ++i) {
            this->drug_arry[i]->ShowDrug();
            cout << " 库存:" << this->drug_arry[i]->stockpile << endl;
        }
    }
    system("pause");
}

void DrugManagement::StatisticDay() {
    cout << "您需要统计哪一天的营业额?" << endl;
    Date date;
    cout << "年: ";
    cin >> date.year;
    cout << "月: ";
    cin >> date.month;
    cout << "日: ";
    cin >> date.day;
    double day_statistic = 0;
    for (int i = 0; i < this->number_out_goods; ++i) {
        if (this->shipping_arry[i]->good.selling_time.year == date.year &&
            this->shipping_arry[i]->good.selling_time.month == date.month &&
            this->shipping_arry[i]->good.selling_time.day == date.day) {
            int index = this->IsDrug(this->shipping_arry[i]->code1);
            day_statistic += (this->drug_arry[index]->prices * this->shipping_arry[i]->good.out_number);
        }
    }
    cout << "日营业额: " << day_statistic << endl;
}
void DrugManagement::StatisticMonth() {
    cout << "您需要统计哪一个月的营业额?" << endl;
    Date date;
    cout << "年: ";
    cin >> date.year;
    cout << "月: ";
    cin >> date.month;
    double month_statistic = 0;
    for (int i = 0; i < this->number_out_goods; ++i) {
        if (this->shipping_arry[i]->good.selling_time.year == date.year &&
            this->shipping_arry[i]->good.selling_time.month == date.month) {
            int index = this->IsDrug(this->shipping_arry[i]->code1);
            month_statistic += (this->drug_arry[index]->prices * this->shipping_arry[i]->good.out_number);
        }
    }
    cout << "月营业额: " << month_statistic << endl;
}
void DrugManagement::StatisticQuarter() {
    cout << "您需要统计哪个季度的营业额?" << endl;
    int year, quarter;
    cout << "年份: ";
    cin >> year;
    cout << "季度 (1-4): ";
    cin >> quarter;

    // 确定季度的月份范围
    int startMonth = (quarter - 1) * 3 + 1;
    int endMonth = startMonth + 2;

    double quarter_statistic = 0;
    for (int i = 0; i < this->number_out_goods; ++i) {
        if (this->shipping_arry[i]->good.selling_time.year == year &&
            this->shipping_arry[i]->good.selling_time.month >= startMonth &&
            this->shipping_arry[i]->good.selling_time.month <= endMonth) {
            int index = this->IsDrug(this->shipping_arry[i]->code1);
            quarter_statistic += (this->drug_arry[index]->prices * this->shipping_arry[i]->good.out_number);
        }
    }
    cout << "第 " << quarter << " 季度的营业额: " << quarter_statistic << endl;
}
void DrugManagement::StatisticYear() {
    cout << "您需要统计哪一年的营业额?" << endl;
    int year;
    cout << "年: ";
    cin >> year;
    double year_statistic = 0;
    for (int i = 0; i < this->number_out_goods; ++i) {
        if (this->shipping_arry[i]->good.selling_time.year == year) {
            int index = this->IsDrug(this->shipping_arry[i]->code1);
            year_statistic += (this->drug_arry[index]->prices * this->shipping_arry[i]->good.out_number);
        }
    }
    cout << "年营业额: " << year_statistic << endl;
}
void DrugManagement::StatisticCategory() {
    cout << "您需要统计哪个类别的药品营业额?" << endl;
    string category;
    cout << "药品类别: ";
    cin >> category;

    double category_statistic = 0;
    for (int i = 0; i < this->number_out_goods; ++i) {
        int index = this->IsDrug(this->shipping_arry[i]->code1);
        if (index != -1 && this->drug_arry[index]->category == category) {
            category_statistic += (this->drug_arry[index]->prices * this->shipping_arry[i]->good.out_number);
        }
    }
    cout << "类别为 " << category << " 的药品营业额: " << category_statistic << endl;
}
DrugManagement::~DrugManagement() {
    for (int i = 0; i < this->number_drug; ++i) {
        delete this->drug_arry[i]; 
    }
    delete[] this->drug_arry;
}

Drug::Drug(string name, int code, string category, double prices) {
    this->name = name;
    this->code = code;
    this->category = category;
    this->prices = prices;
}
void Drug::ShowDrug() {
    cout << "药品名称: " << name << " 药品编码: " << code << " 药品类别: " << category
        << " 药品价格: " << prices << "元";
}
Drug::~Drug() {

}

Warehouse::Warehouse(string name, int code, string category, double prices) :Drug(name, code, category, prices){
    stockpile = 0;
}
Warehouse::Warehouse(string name) : Drug(name, 0, "", 0.0) {
    stockpile = 0;
    good.production_date.year = 0;
    good.production_date.month = 0;
    good.production_date.day = 0;
    good.date_of_use.year = 0;
    good.date_of_use.month = 0;
    good.date_of_use.day = 0;
    good.inventory_time.year = 0;
    good.inventory_time.month = 0;
    good.inventory_time.day = 0;
    good.in_number = 0;
    good.out_number = 0;
    good.selling_time.year = 0;
    good.selling_time.month = 0;
    good.selling_time.day = 0;

}
void Warehouse::ShowInGoods() {
    cout << "药品名称: " << name << " 进货量: " << good.in_number << endl;
    cout << "生产日期: ";
    PrintDate(good.production_date);
    cout << " 使用期限: ";
    PrintDate(good.date_of_use);
    cout << " 入库时间: ";
    PrintDate(good.inventory_time);
    cout << endl;
}
void Warehouse::ShowOutGoods() {
    cout << "药品名称: " << name1 << " 出售量: " << good.out_number << endl;
    cout << "出库时间: ";
    PrintDate(good.selling_time);
    cout << endl;
}
Warehouse::~Warehouse() {

}

药店管理.cpp(主程序)

#include "DrugManagement.h"

int choice;
int choice1;
int choice2;
int choice3;
int choice4;
DrugManagement dm;
string password_G = "20050528";
int main() {
    while (true) {
        dm.ShowMenu00();
        cin >> choice;
        switch (choice) {
        case 0:
            dm.ExitSystem();
            break;
        case 1: {//员工
            system("cls");
            while (true) {
                dm.ShowMenu03();
                dm.AutomaticWarningStockpile();
                dm.AutomaticWarningDate();
                cout << "请输入您的选择: ";
                cin >> choice1;
                if (choice1 == 0) {
                    system("cls");
                    cout << "已返回上一界面:" << endl;
                    break;
                }
                switch (choice1) {
                case 1: {
                    dm.Shipping();
                    system("pause");
                    system("cls");
                }
                    break;
                case 2: {
                    dm.Receiving();
                    system("pause");
                    system("cls");
                }
                    
                    break;
                case 3: {
                    system("cls");
                    while (true) {
                        dm.ShowMenu04();
                        cin >> choice3;
                        if (choice3 == 0) {
                            system("cls");
                            cout << "已返回上一界面:" << endl;
                            break;
                        }
                        switch (choice3) {
                        case 1: {
                            dm.FindDrug();
                            system("pause");
                            system("cls");
                        }

                              break;
                        case 2: {
                            dm.ShowShipping();
                            system("cls");
                        }

                              break;
                        case 3: {
                            dm.ShowReceiving();
                            system("cls");
                        }

                              break;
                        case 4: {
                            dm.ShowDrug();
                            system("cls");
                        }

                              break;
                        default:
                            system("cls");
                            cout << "无效选择,请重新输入!" << endl;
                            break;
                        }
                    }
                }
                    
                    break;
                case 4: {
                    system("cls");
                    while (true) {
                        dm.ShowMenu05();
                        cin >> choice4;
                        if (choice4 == 0) {
                            system("cls");
                            cout << "已返回上一界面:" << endl;
                            break;
                        }
                        switch (choice4) {
                        case 1: {
                            dm.StatisticDay();
                            system("pause");
                            system("cls");
                        }

                              break;
                        case 2: {
                            dm.StatisticMonth();
                            system("pause");
                            system("cls");
                        }

                              break;
                        case 3: {
                            dm.StatisticQuarter();
                            system("pause");
                            system("cls");
                        }

                              break;
                        case 4: {
                            dm.StatisticYear();
                            system("pause");
                            system("cls");
                        }

                              break;
                        case 5: {
                            dm.StatisticCategory();
                            system("pause");
                            system("cls");
                        }

                              break;
                        default:
                            system("cls");
                            cout << "无效选择,请重新输入!" << endl;
                            break;
                        }
                    }
                }
                    
                    break;
                default:
                    system("cls");
                    cout << "无效选择,请重新输入!" << endl;
                    break;
                }
            }
        }   
              break;
        case 2:{//管理员           
            system("cls");
            string password_g;
            cout << "请输入管理员密码以进入系统设置界面: " << endl;
            cin >> password_g;

            if (password_g == password_G) {
                cout << "密码正确,正在进入系统···" << endl;
                system("pause");
                system("cls");
                while (true) {
                    dm.ShowMenu02();
                    cin >> choice2;
                    if (choice2 == 0) {
                        system("cls");
                        cout << "已返回上一界面:" << endl;
                        break;
                    }
                    switch (choice2) {
                    case 1:
                        dm.AddDrug();
                        system("cls");
                        break;
                    case 2:
                        dm.DeleteDrug();
                        system("cls");
                        break;
                    case 3:
                        dm.ModifyDrug();
                        system("cls");
                        break;
                    default:
                        system("cls");
                        cout << "无效选择,请重新输入!" << endl;
                        break;
                    }
                }
            }
        }
              break;
        default:
            system("cls");
            cout << "无效选择,请重新输入!" << endl;
            break;
        }
    }



    return 0;
}

三. 系统详细设计

1. 系统菜单设计

菜单层级 功能选项
主菜单 1.员工登录 2.管理员登录(需密码验证)
员工菜单 1. 进货入库 2. 销售出库 3. 查询信息(药品查询、进货记录、销售记录、药品目录) 4. 统计数据(日、月、季、年、分类销售额)
管理员菜单 1.添加药品 2.删除药品 3.修改药品

2. 系统功能详细设计

1.添加药品:
输入名称、类别、价格,自动生成唯一编码(1001起始)。
动态扩展数组drug_arry并保存至drug.txt。
2.进货流程:
输入药品编码、数量、生产日期、保质期,自动记录入库时间。
更新库存并保存至shipping.txt。
3.销售流程:
输入药品编码、数量,自动记录出库时间。
更新库存并保存至receiving.txt。
4.过期清理:
比对当前日期与保质期,触发预警后需输入“清理”确认操作。
删除过期记录并更新文件。

四. 测试及测试结果

  1. 进货入库记录
    测试步骤:
    1.启动系统,选择员工身份。
    2.选择进货入库功能,输入药品编码(假设已存在编码为 1001 的药品)。
    3 输入进货数量、生产日期(2023-01-01)、保质期(2025-01-01)。
    4.检查 shipping.txt 文件是否新增记录。
    5.检查库存量是否增加。
    预期结果:
    • 文件 shipping.txt 中新增一条记录,包含进货信息。
    • 药品库存量正确增加。
    实际结果:
    • ✅ 文件记录正确,库存更新成功。

  1. 销售出货记录
    测试步骤:
    1 选择销售出库功能,输入药品编码 1001 和销售数量 5。
    2.检查 receiving.txt 文件是否新增记录。
    3.检查库存量是否减少。
    预期结果:
    • 文件 receiving.txt 中新增一条记录,包含销售时间和数量。
    • 库存量减少 5。
    实际结果:
    • ✅ 销售记录保存正确,库存更新无误。

  1. 药品信息查询
    测试步骤:
    1.选择查询信息 → 查询药品。
    2.输入药品编码 1001,查看详细信息。
    3.输入药品名称(如 阿莫西林),查看详细信息。
    预期结果:
    •显示药品名称、类别、价格、库存、生产日期、保质期等。
    实际结果:
    • ✅ 通过编码和名称均能正确查询到完整信息。

  1. 自动预警提示
    测试步骤:
    1.手动修改 drug.txt,将某药品库存设置为 5(阈值 MIN=10)。
    2.重启系统,观察是否触发库存预警。
    3.修改某进货记录的保质期为过去日期,观察临期预警。
    预期结果:
    • 库存低于 10 时提示“请注意及时补充”。
    • 临期药品提示“已过保质期,请清理”。
    实际结果:
    • ✅ 库存预警正常触发。
    • ✅ 输入“清理”后记录被删除,库存同步更新。

  1. 统计功能
    测试步骤:
    1.添加多笔销售记录,覆盖不同日期、月份、类别。
    2.选择统计功能,分别测试日、月、季度、年、类别统计。
    预期结果:
    • 统计结果与输入数据一致。
    实际结果:
    • ✅ 日营业额正确累加当日销售数据。
    • ✅ 类别统计仅计算指定类别的销售额。

  1. 异常测试
    测试内容:
    • 输入非法数据(如负数的进货数量、不存在的药品编码)。
    • 管理员密码错误。
    • 删除不存在的药品。
    预期结果:
    • 系统提示错误,拒绝操作。
    实际结果:
    • ✅ 负数进货提示“必须为正数”。
    • ✅ 密码错误无法进入管理员界面。
    • ✅ 删除无效编码提示“未找到该药品”。

测试总结
• 通过率: 100%
• 核心功能: 进货、销售、查询、预警、统计均正常。
测试结论: 系统满足设计要求,功能完整且稳定。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值