0
点赞
收藏
分享

微信扫一扫

综合项目三----包裹的旅行

WikongGuan 2022-03-12 阅读 41

【问题描述】

包裹的旅行综合项目:从解决实际问题出发,以“包裹的旅行”项目进行研究,通过“购物体验”“订单管理”“物流运输”“智取包裹”四个环节,依次剖析数据的类型以及队列、树、图等数据结构。通过分析生活中的实际问题,培养学生的抽象建模能力,进而提高其运用所学知识解决问题的能力。

【具体要求】

1、购物体验之认识数据类型。设计网站购物的物品的具体信息,分析对象并抽象出合适的数据类型,定义存储结构。例如商品名称、单价、数量等,订单中包含的数据等。

2、订单管理之线性数据结构:队列。分析商家对订单有哪些管理操作,根据队列的特点,讨论卖家对订单的处理,如何排单、如何安排发货等,实现订单管理功能的具体编码。

3、物流运输之树形数据结构。分析包裹的运输路线,物流详细安排。设计一些城市和物流站点,实现树状结构的物流信息表示。

4、智取包裹之图形数据结构。通过对取包裹路线的分析,抽象出点线面的关系,并建立图的模型,计算出取包裹的最快路线。

5、自行设计项目后台数据,自行设计展示平台进行动态演示。

#include<bits/stdc++.h>
#include<windows.h>
#include <fstream>
using namespace std;
#define N 6
#define INF 32767

/// -----------数据定义--------------
///二维数组 智取包裹路径 ---孟
int A1[N][N],A2[N][N],A3[N][N],A4[N][N];
///定义商品的存储结构 --张
struct goods
{
    int no;				    ///商品序号
    string name;			///商品名称
    double price;		    ///商品价格
    int last_nums;		    ///商品库存
} Goods[4]=
{
    {1,"Book",98,88}, 		///书  ——普林斯顿微积分读本
    {2,"T_shirt",89,94}, 	///T恤 ——日系T恤潮流风
    {3,"Skirt",239,92}, 	///裙子——瑶瑶公主遇见神鹿联名款
    {4,"Toys",205,85} 		///玩具——迪迦奥特曼精致手办
};
/// 矩阵 -- 何
struct Graph
{
    int arcs[11][11];
    int vexnum=11;
};
/// 路径 -- 何
struct Path_logistics
{
    int dist;
    int path;
};
Graph g;
Path_logistics p[11][11];
///买家订单中购买的商品信息---张
typedef struct buyers
{
    string name_goods;			///购买的商品名称
    double price;		///购买的商品价格
    int bought_nums;	///购买的商品数量
    struct buyers *next;///链接买家订单中的下一个商品
} Buyers;
///客户结构体 ---张
typedef struct customer
{
    Buyers *p; ///商品
    string name_customer; ///名称
    string mima; ///密码
    int address_id; ///地址代号
    int Count;///总数
    struct customer *next;///指向下一个客户
    int order_timen[6];///下单时间
    int issue_timen[6];///出单时间
    int flag;///商家是否出单
} Customer;
///商家结构体 ---刘
typedef struct bussiness
{
    Customer *p;
    string name;
    string mima;
    int count_customer;
} Bussiness;
Bussiness *bu;

/// ------------函数声明----------
void Create_logistics();
void output(int s,int t);
void Transport_customer(int en);
void goods_show();
void Transport_Business();
void time(int *timen);
void show_time(int *timen);
void CusIno_show();
void Buy(int n,Customer *&cu);
void goods_menu();
void Customer_show(Customer *cu);
void address_menu();
void SelectGoods(Customer *&cu);
void Create_Route1();
void Create_Route2();
void ShortPath(int path[][N],int i,int j);
void Floyd_1(int address_id);
void Floyd_2(int address_id);
void Message();
void Start();
void Login_Sellers();
void Login_Buyers(Customer *&cu);
int Menu__Sellers();
int Menu__Buyers();
void Main__Sellers();
void Main__Buyers();

/// -------------函数实现---------
///创建矩阵 ---何
void Create_logistics()
{
    ifstream infile;
    infile.open("logistics.txt",ios::in);
    if(!infile.is_open())
    {
        cout<<" 未成功打开文件 "<<endl;
    }
    for(int i=0; i<g.vexnum; i++)
        for(int j=0; j<g.vexnum; j++)
        {
            int w;
            infile>>w;
            if(w==0)
                g.arcs[i][j]=INF;
            else
                g.arcs[i][j]=w;
        }
}
///输出物流 ---何
void output(int s,int t)
{
    if(p[s][t].path)
    {
        output(s,p[s][t].path);
        switch(p[s][t].path)
        {
        case 1:
            cout<<"北京->";
            break;
        case 2:
            cout<<"石家庄->";
            break;
        case 3:
            cout<<"太原->";
            break;
        case 4:
            cout<<"南昌->";
            break;
        case 5:
            cout<<"南京->";
            break;
        case 6:
            cout<<"广州->";
            break;
        case 7:
            cout<<"成都->";
            break;
        case 8:
            cout<<"郑州->";
            break;
        case 9:
            cout<<"西安->";
            break;
        case 10:
            cout<<"呼和浩特->";
            break;
        }
    }
}
///计算最短路 ---何
void Transport_customer(int en)
{
    for(int i=0; i<g.vexnum; i++)
        for(int j=0; j<g.vexnum; j++)
        {
            if(i!=j)
                p[i][j].dist=g.arcs[i][j];
            else
                p[i][j].dist=0;
        }
    int visited[11];
    for(int i=0; i<11; i++)
        visited[i]=0;
    for(int i=0; i<g.vexnum; i++)
    {
        visited[i]=1;
        for(int j=0; j<g.vexnum; j++)
        {
            for(int k=0; k<g.vexnum; k++)
            {
                if(p[j][k].dist>p[j][i].dist+p[i][k].dist)
                {
                    p[j][k].dist=p[j][i].dist+p[i][k].dist;
                    p[j][k].path=i;
                }
            }
        }
    }
    cout<<"运输时长 ";
    cout<<p[0][en].dist<<"天"<<endl;
    cout<<"运输路径:武汉->";
    output(0,en);
    switch(en)
    {
    case 1:
        cout<<"北京";
        break;
    case 2:
        cout<<"石家庄";
        break;
    case 3:
        cout<<"太原";
        break;
    case 4:
        cout<<"南昌";
        break;
    case 5:
        cout<<"南京";
        break;
    case 6:
        cout<<"广州";
        break;
    case 7:
        cout<<"成都";
        break;
    case 8:
        cout<<"郑州";
        break;
    case 9:
        cout<<"西安";
        break;
    case 10:
        cout<<"呼和浩特";
        break;
    }
    cout<<endl;

}
///商品显示 ---刘
void goods_show()
{
    cout<<"商品序号     商品名称 商品价格 商品库存"<<endl;
    for(int i = 0; i<4; i++)
        cout<<"    "<<Goods[i].no<<"\t\t"<<Goods[i].name<<'\t'<<Goods[i].price<<'\t'<<Goods[i].last_nums<<endl;

}
///用户物流显示 ---刘
void Transport_Business()
{
    Customer *p;
    p = bu->p->next;
    while(p)
    {
        cout<<"顾客"<<p->name_customer<<"的物流信息如下:"<<endl;
        Transport_customer(p->address_id);
        cout<<"出单时间: ";
        show_time(p->issue_timen);
        cout<<endl;
        p = p->next;
    }
}
///获取当前时间 ---刘
void time(int *timen)
{
    time_t now;
    struct tm *fmt;
    time(&now);
    fmt = localtime(&now);
    timen[0]=fmt->tm_year+1900;
    timen[1]=fmt->tm_mon+1;
    timen[2]=fmt->tm_mday;
    timen[3]=fmt->tm_hour;
    timen[4]=fmt->tm_min;
    timen[5]=fmt->tm_sec;
}
///输出当前时间 ---刘
void show_time(int *timen)
{
    for(int i=0; i<6; i++)
    {
        if(i<3)
            cout<<timen[i]<<".";
        else if(i==3)
        {
            cout<<" ";
            cout<<setfill('0')<<setw(2)<<timen[i];
        }
        else if(i>3)
            cout<<":"<<setfill('0')<<setw(2)<<timen[i];
    }
}
///用户信息显示 ---刘
void CusIno_show()
{
    Customer *p;
    p = bu->p->next;
    if(!p)
        cout<<"当前还未有顾客下单"<<endl;
    while(p)
    {
        cout<<"顾客姓名:"<<p->name_customer<<endl;
        cout<<"顾客";
        Customer_show(p);
        cout<<"顾客地址为:";
        switch(p->address_id)
        {
        case 1:
            cout<<"北京";
            break;
        case 2:
            cout<<"石家庄";
            break;
        case 3:
            cout<<"太原";
            break;
        case 4:
            cout<<"南昌";
            break;
        case 5:
            cout<<"南京";
            break;
        case 6:
            cout<<"广州";
            break;
        case 7:
            cout<<"成都";
            break;
        case 8:
            cout<<"郑州";
            break;
        case 9:
            cout<<"西安";
            break;
        case 10:
            cout<<"呼和浩特";
            break;
        }
        cout<<endl;
        cout<<"顾客下单时间:";
        show_time(p->order_timen);
        cout<<endl;
        time(p->issue_timen);
        cout<<"订单出库时间:";
        show_time(p->issue_timen);
        cout<<endl;
        p->flag = 1;
        p = p->next;
    }
}
///买家购买商品操作(链表--商品链接)---张
void Buy(int n,Customer *&cu)
{
    int buynum; ///购买的商品数量
    cout<<"请输入您想要购买此商品的数量"<<endl;
    cin>>buynum;
    cu->Count += buynum;
    Buyers *q;
    q = new Buyers;
    q->name_goods = Goods[n-1].name;
    q->price = Goods[n-1].price*buynum;
    q->bought_nums=buynum;
    Goods[n-1].last_nums -= buynum; ///修改库存
    q->next = cu->p->next;
    cu->p->next = q;
}
///显示商品菜单 ---张
void goods_menu()
{
    cout<<"请从以下商品中选择您想要购买的商品:"<<endl;
    cout<<"-----------------------------------------------------------------"<<endl;
    cout<<"       商品名称                        商品价格(元)    剩余库存"<<endl;
    cout<<"1. 书——普林斯顿微积分读本                "<<Goods[0].price<<"               "<<Goods[0].last_nums<<endl;
    cout<<"2. T恤——日系T恤潮流风                    "<<Goods[1].price<<"               "<<Goods[1].last_nums<<endl;
    cout<<"3. 裙子——瑶瑶公主遇见神鹿联名款         "<<Goods[2].price<<"               "<<Goods[2].last_nums<<endl;
    cout<<"4. 玩具——迪迦奥特曼精致手办             "<<Goods[3].price<<"               "<<Goods[3].last_nums<<endl;
    cout<<"-----------------------------------------------------------------"<<endl;
}
///用户清单显示  ---张
void Customer_show(Customer *cu)
{
    float sum;
    Buyers *p;
    p = cu->p->next;
    cout<<"购买的商品如下:"<<endl;
    cout<<"商品名称     商品总价     商品数量"<<endl;
    while(p)
    {
        sum += p->price;
        cout<<p->name_goods<<"\t\t"<<p->price<<"\t\t"<<p->bought_nums<<endl;
        p = p->next;
    }
    cout<<"总"<<cu->Count<<"件商品,总价格为"<<sum<<endl;
    cout<<"下单时间为:";
    show_time(cu->order_timen);
    cout<<endl;
}

///显示地址菜单  ----张
void address_menu()
{
    cout<<"请从下列地址中选择您想要收货的地址:"<<endl;
    cout<<"----------------------------------"<<endl;
    cout<<"1.北京"<<endl;
    cout<<"2.石家庄"<<endl;
    cout<<"3.太原"<<endl;
    cout<<"4.南昌"<<endl;
    cout<<"5.南京"<<endl;
    cout<<"6.广州"<<endl;
    cout<<"7.成都"<<endl;
    cout<<"8.郑州"<<endl;
    cout<<"9.西安"<<endl;
    cout<<"10.呼和浩特"<<endl;
    cout<<"----------------------------------"<<endl;
}
///用户选择商品  ----张
void SelectGoods(Customer *&cu)
{

    int number=0,cou = 0;
    int flag = 0;
    do
    {
        goods_menu();   ///显示商品菜单
        do
        {
            if(cou)
            {
                cout<<"请正确输入序号:"<<endl;
            }
            cin>>number;
            cou++;
        }
        while(number<1 || number > 4);
        cou = 0;
        switch(number)
        {
        case 1:
            Buy(1,cu);
            break;
        case 2:
            Buy(2,cu);
            break;
        case 3:
            Buy(3,cu);
            break;
        case 4:
            Buy(4,cu);
            break;
        }
        cout<<"是否还选择其他商品,是输入 1,否请输入0"<<endl;
        cin>>flag;
    }
    while(flag);
    system("pause");
    system("cls");
    address_menu();	///显示地址选择菜单
    int location;	///设选送货地点的变量
    cin>>location;
    cu->address_id = location;
}
///创建数据1 ---孟
void Create_Route1()
{
    ifstream infile;
    infile.open("round-1.txt",ios::in);
    if(!infile.is_open())
    {
        cout<<" 未成功打开文件 "<<endl;
    }
    for(int i = 0; i<N; i++)
        for(int j = 0; j<N; j++)
        {
            int w;
            infile>>w;
            if(w)
                A1[i][j] = w;
            else
                A1[i][j] = INF;
        }
    for(int i = 0; i<N; i++)
        for(int j = 0; j<N; j++)
            A2[j][i] = A1[i][j];
}
///创建数据2 --- 孟
void Create_Route2()
{
    ifstream infile;
    infile.open("round-2.txt",ios::in);
    if(!infile.is_open())
    {
        cout<<" 未成功打开文件 "<<endl;
    }
    for(int i = 0; i<N; i++)
        for(int j = 0; j<N; j++)
        {
            int w;
            infile>>w;
            if(w)
                A2[i][j] = w;
            else
                A3[i][j] = INF;
        }
    for(int i = 0; i<N; i++)
        for(int j = 0; j<N; j++)
            A4[j][i] = A3[i][j];
}
///输出最短路 ---孟
void ShortPath(int path[][N],int i,int j)
{
    int k;
    k = path[i][j];
    if(k)
    {
        ShortPath(path,i,k);
        cout<<k<<" --> ";
        ShortPath(path,k,j);
    }
}
///求最短路 ---智取包裹 ----孟
void Floyd_1(int address_id)
{
    int B[N][N],path[N][N];
    if(address_id % 2 == 0)
    {
        for(int i = 0; i<N; i++)
        {
            for(int j = 0; j<N; j++)
                B[i][j] = A1[i][j],path[i][j] = 0;
            B[i][i] = 0;
        }
    }
    else
    {
        for(int i = 0; i<N; i++)
        {
            for(int j = 0; j<N; j++)
                B[i][j] = A3[i][j],path[i][j] = 0;
            B[i][i] = 0;
        }
    }
    for(int k = 0; k<N; k++)
        for(int i = 0; i<N; i++)
            for(int j = 0; j<N; j++)
                if(B[i][j] > B[i][k] + B[k][j])
                    B[i][j] = B[i][k] + B[k][j],path[i][j] = k;
    cout<<"路线为:"<<endl;
    cout<<"家到菜鸟驿站的最短路径为:"<<B[0][N-1]<<"  路线为:";
    cout<<"0 --> ";
    ShortPath(path,0,N-1);
    cout<<N-1<<endl;
}
///求最短路 ---回家路线 ----孟
void Floyd_2(int address_id)
{
    int B[N][N],path[N][N];
    if(address_id % 2 == 0)
    {
        for(int i = 0; i<N; i++)
        {
            for(int j = 0; j<N; j++)
                B[i][j] = A2[i][j],path[i][j] = 0;
            B[i][i] = 0;
        }
    }
    else
    {
        for(int i = 0; i<N; i++)
        {
            for(int j = 0; j<N; j++)
                B[i][j] = A4[i][j],path[i][j] = 0;
            B[i][i] = 0;
        }
    }
    for(int k = 0; k<N; k++)
        for(int i = 0; i<N; i++)
            for(int j = 0; j<N; j++)
                if(B[i][j] > B[i][k] + B[k][j])
                    B[i][j] = B[i][k] + B[k][j],path[i][j] = k;
    cout<<"路线为:"<<endl;
    cout<<"菜鸟驿站到家的最短路径为:"<<B[0][N-1]<<"  路线为:";
    cout<<N-1<<" --> ";
    ShortPath(path,0,N-1);
    cout<<0<<endl;
}
///弹出框  ---孟
void Message()
{
    int i=MessageBox(NULL,
                     "欢迎使用文本编译器程序 ! \n\
                     本程序开发人员:xxx,xx,xxx,xxx",
                     "文本编译器",MB_OK);
    return ;
}
///开始界面  ---孟
void Start()
{
    cout<<"***********************************"<<endl;
    cout<<"*                                 *"<<endl;
    cout<<"*               欢                *"<<endl;
    cout<<"*               迎                *"<<endl;
    cout<<"*               来                *"<<endl;
    cout<<"*               到                *"<<endl;
    cout<<"*               简                *"<<endl;
    cout<<"*               易                *"<<endl;
    cout<<"*               购                *"<<endl;
    cout<<"*               物                *"<<endl;
    cout<<"*               程                *"<<endl;
    cout<<"*               序                *"<<endl;
    cout<<"*                                 *"<<endl;
    cout<<"***********************************"<<endl;
}
///登录界面--卖家  ---孟
void Login_Sellers()
{
    system("cls");
    string name;
    string mima = "123456",mima1;
    bu->mima = mima;
    cout<<"请输入商家名称:"<<endl;
    cin>>name;
    cout<<"请输入商家密码:"<<endl;
    cin>>mima1;
    while(1)
    {
        if(mima == mima1 && name == bu->name)
        {
            cout<<"欢迎商家"<<name<<"登录成功"<<endl;
            break;
        }
        else if(mima != mima1)
        {
            cout<<"密码错误,请重新输入:"<<endl;
            cin>>mima1;
        }
        else
        {
            cout<<"用户名错误,请重新输入:"<<endl;
            cin>>name;
        }
    }
}
///登录界面--买家  ---孟
void Login_Buyers(Customer *&cu)
{
    system("cls");
    string name;
    string mima = "123456",mima1;
    cout<<"请输入用户名称:"<<endl;
    cin>>name;
    cu->name_customer = name;
    cu->mima = mima;
    cout<<"请输入用户密码:"<<endl;
    cin>>mima1;
    while(1)
    {
        if(mima == mima1)
        {
            cout<<"欢迎用户"<<name<<"登录成功"<<endl;
            break;
        }
        else
        {
            cout<<"密码错误,请重新输入:"<<endl;
            cin>>mima1;
        }
    }

}
///菜单--卖家  ---刘
int Menu__Sellers()
{
    cout<<"请根据提示进行相应的操作"<<endl;
    cout<<" 1:退出登录"<<endl;
    cout<<" 2:商品信息"<<endl;
    cout<<" 3: 用户购买信息"<<endl;
    cout<<" 4: 物流信息"<<endl;
    int choice;
    do
    {
        cin>>choice;
    }
    while(choice < 1 || choice > 4);
    return choice;
}
///菜单--买家  ----张
int Menu__Buyers()
{
    cout<<"请根据提示进行相应的操作"<<endl;
    cout<<" 1:退出登录"<<endl;
    cout<<" 2:购买商品"<<endl;
    cout<<" 3: 清单信息"<<endl;
    cout<<" 4: 物流信息"<<endl;
    cout<<" 5: 智取包裹路线"<<endl;
    int choice;
    do
    {
        cout<<"请输入选择"<<endl;
        cin>>choice;
    }
    while(choice < 1 || choice > 5);
    return choice;
}

///商家主程序 ---刘
void Main__Sellers()
{
    int choice1;
    int flag = 0;///标记
    Login_Sellers();
    while(1)
    {
        system("pause");
        system("cls");
        choice1 = Menu__Sellers();
        switch(choice1)
        {
        case 1:
            flag = 1;
            break;
        case 2:
            goods_show();
            break;
        case 3:
            CusIno_show();
            break;
        case 4:
            Transport_Business();
            break;
        }
        if(flag)
        {
            cout<<"成功退出"<<endl;
            break;
        }
    }

}
///用户主程序  ---张
void Main__Buyers()
{
    int choice1;
    int flag = 0,num = 0;///标记
    Customer *cu;
    cout<<"是否为新顾客 \n 是输入 1 \n 不是输入 0"<<endl;
    cin>>num;
    if(bu->count_customer == 0 || num)
    {
        cu = new Customer;
        cu->p = new Buyers;
        cu->p->next = NULL;
        cu->next = NULL;
        cu->Count = 0;
        cu->flag = 0;
        Login_Buyers(cu);
        if(bu->count_customer == 0)
            bu->p->next = cu;
        else
        {
            Customer *r,*q;
            r = bu->p->next;
            while(r)
            {
                q = r;
                r = r->next;
            }
            q->next = cu;
        }
        bu->count_customer++;
    }
    else
    {
        system("cls");
        string name;
        string mima = "123456",mima1;
        cout<<"请输入用户名称:"<<endl;
        cin>>name;
        cout<<"请输入用户密码:"<<endl;
        cin>>mima1;
        Customer *r,*q;
        r = bu->p->next;
        while(r->name_customer != name)
        {
            q = r;
            r = r->next;
        }
        if(r)
            cu = r;
    }
    time(cu->order_timen);

    while(1)
    {
        system("pause");
        system("cls");
        choice1 = Menu__Buyers();
        switch(choice1)
        {
        case 1:
            flag = 1;
            break;
        case 2:
            SelectGoods(cu);
            break;
        case 3:
            Customer_show(cu);
            break;
        case 4:
            if(cu->flag)
            {
                cout<<"订单出库时间:";
                show_time(cu->issue_timen);
                cout<<endl;
                Transport_customer(cu->address_id);
            }
            else
                cout<<"商家还未出单,请你在等一会"<<endl;
            break;
        case 5:
            Floyd_1(cu->address_id);
            Floyd_2(cu->address_id);
            break;
        }
        if(flag)
        {
            cout<<"成功退出"<<endl;
            system("pause");
            break;
        }
    }
}

///--------------主函数---------
///主函数 --- 小组全部成员
int main()
{
    bu = new Bussiness;
    bu->p = new Customer;
    bu->p->next = NULL;
    bu->count_customer = 0;
    bu->name = "wuhan";
    int choice_id;///选择身份
    Message();
    Start();
    Create_Route1();
    Create_Route2();
    Create_logistics();
    system("pause");
mmap:
    system("cls");
    cout<<endl<<endl;
    cout<<"\t请选择你的身份:\n\t 卖家输入 1 \n\t 买家输入 2  \n\t 退出程序输入 3"<<endl;
    cin>>choice_id;
    switch(choice_id)
    {
    case 1:
        Main__Sellers();
        goto mmap;
        break;
    case 2:
        Main__Buyers();
        goto mmap;
        break;
    case 3:
        cout<<"欢迎下次光临"<<endl;
        exit(0);
        break;
    }
    return 0;
}

所需文件:

  • round-1
0 2 5 0 0 0
0 0 1 0 0 0
0 0 0 2 4 7
0 0 0 0 0 1
0 0 0 0 0 1
  • round-2
0 2 5 0 0 0
0 0 1 0 0 0
0 0 0 2 4 7
0 0 0 0 0 1
0 0 0 0 0 1

  • logistics
0 0 0 0 1 0 4 2 2 0 0
0 0 1 1 0 0 0 0 0 0 0
0 1 0 0 2 0 0 0 0 0 0
0 1 0 0 1 0 0 0 0 0 3
1 0 2 1 0 1 3 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0
4 0 0 0 3 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 1 0
2 0 0 0 0 0 0 0 0 2 2
0 0 0 0 0 0 0 1 2 0 0
0 0 0 3 0 0 0 0 2 0 0

举报

相关推荐

0 条评论