某停车场车辆出入库模拟系统

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<windows.h>
using namespace std;

void GotoXY(int x, int y)  // 移动 
{
    HANDLE hout;  //屏幕尺寸 变量 
    COORD coord={x,y};  //光标坐标 变量  光标x标  光标y标 
    hout=GetStdHandle(STD_OUTPUT_HANDLE);  //获得屏幕尺寸 
    SetConsoleCursorPosition(hout,coord);  //移动光标 
}
bool isLeapYear(int year)
    //判断是否为闰年 
{
    return ((year%4==0 && year%100!=0) || year%400==0);
}

int getDays(int year, int month, int day)
    // 以公元 1 年 1 月 1 日为基准,计算经过的日期 
{
    int m[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    
    if(isLeapYear(year))
    {
        m[2]++;
    }
    
    int result = 0;
    
    for(int i = 1;i < year;i++)
    {
        result += 365;
        if(isLeapYear(i))
        {
            result ++;
        }
    }
    for(int i = 1;i < month;i++)
    {
        result += m[i];
    }
    result += day;
    
    return result;
}
int dayDis(    int year1,    int month1,    int day1,
            int year2,    int month2,    int day2)
    //计算日期差 
{
    return abs(getDays(year2, month2, day2) - getDays(year1, month1, day1));
}

class customer//顾客信息 
{
    public:
        string name;        //顾客姓名 
        string license;     //顾客车牌号 
        //入库时间 
        int yearin;
        int monthin;
        int dayin;
        int hourin;
        int minutein;
        
        int yearout;        //出库时间 
        int monthout;
        int dayout;
        int hourout;
        int minuteout;
        int starlevel;
        
        int the_time;        //停车时长 
        
        float the_money;        //停车价格 
};
class allcustomer
{
    public:
        customer line[20]; 
        
        float them0;        //0星会员每小时收费 them0 元 
        
        int the1fd;            //1星会员收费分the1fd段 
        int the1j[10];        //1星会员收费每段收费截止到 the1j[i]时 
        float the1em[10];    //1星会员每段每小时收费 the1em[i] 元 
        
        float them2;        //2星会员每小时收费 them2 元 
        int the2fd;            //2星会员收费分the2fd段 
        float the2j[10];    //2星会员收费每段收费截止到 the2j[i]元时 
        float the2em[10];    //2星会员每段满减为 the2em[i]元
        
        float them3;        //3星会员每小时收费 them3 元 
        
};
void guanli(allcustomer *thep,int Customer_number,string zhanghao,string mima);

void guke(allcustomer *thep,int Customer_number,string zhanghao,string mima);

void set(allcustomer *thep,int Customer_number,string zhanghao,string mima);

void newset(allcustomer *thep,int Customer_number,string zhanghao,string mima);

float money0(allcustomer *thep,int Customer_number,string zhanghao,string mima);

float money1(allcustomer *thep,int Customer_number,string zhanghao,string mima);

float money2(allcustomer *thep,int Customer_number,string zhanghao,string mima);

float money3(allcustomer *thep,int Customer_number,string zhanghao,string mima);

int main()
{
    allcustomer thecustomer;
    //allcustomer *tp;
    //tp=&thecustomer;
    int cnumber; 
    cnumber=0;
    
    string zerozhanghao,zeromima;
    
    zerozhanghao="0";        //初始账号为"0" 
    
    zeromima="0";            //初始密码为"0" 
    
    newset(&thecustomer,cnumber,zerozhanghao,zeromima);
//    retuen 0; 
}
void guanli(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    
    {
        
        printf("输入0设置0星会员收费\n");
        printf("输入1设置1星会员收费\n");
        printf("输入2设置2星会员收费\n");
        printf("输入3设置3星会员收费\n");
        printf("输入5修改管理员账号\n");
        printf("输入6修改管理员密码\n");
        printf("输入8展示所有顾客\n");
        printf("输入9返回\n");
    }
    
    int thechoice;
    cin>> thechoice;
    
    if(thechoice==0)//设置0星会员收费 
    {
        system("cls");
        printf("当前0星会员每小时收费%.2f元\n",thep->them0);
        printf("新设置0星会员每小时收费");
        cin>>thep->them0;
        printf("当前0星会员每小时收费%.2f元\n",thep->them0);
        system("pause");
        set(thep,Customer_number,zhanghao,mima);
    }
    
    if(thechoice==1)//设置1星会员收费 
    {
        system("cls");
        printf("当前1星会员收费分%d段\n",thep->the1fd);
        for(int i=1;i<=thep->the1fd;i++)
        {
            printf("第%d段收费截止到%d时 每小时收费%.2f元\n",i,thep->the1j[i],thep->the1em[i]);
        }
        printf("新设置1星会员收费分多少段\n");
        cin>>thep->the1fd;
        for(int i=1;i<=thep->the1fd;i++)
        {
            printf("第%d段收费截止到多少时\n",i);
            cin>>thep->the1j[i];
            
            printf("每小时收费多少元\n");
            cin>>thep->the1em[i];
        }
        system("pause");
        system("cls");
        printf("当前1星会员收费分%d段\n",thep->the1fd);
        for(int i=1;i<=thep->the1fd;i++)
        {
            printf("第%d段收费截止到%d时 每小时收费%.2f元\n",i,thep->the1j[i],thep->the1em[i]);
        }
        system("pause");
        set(thep,Customer_number,zhanghao,mima);
    }
    
    if(thechoice==2)//设置2星会员收费 
    {
        system("cls");
        
        printf("当前2星会员每小时收费%.2f元\n",thep->them2);
            //2星会员每小时收费 them2 元 
        printf("当前2星会员收费分%d段\n",thep->the2fd);
            //2星会员收费分the2fd段 
        for(int i=1;i<=thep->the1fd;i++)
        {
            printf("折扣%d:满%.2f元减%.2f元\n",i,thep->the2j[i],thep->the2em[i]);
        }
        
        printf("新设置2星会员收费分多少段\n");
        cin>>thep->the2fd;
        
        for(int i=1;i<=thep->the2fd;i++)
        {
            printf("第%d段满减需要达到多少元\n",i);
            cin>>thep->the2j[i];
            
            printf("折扣为多少元\n");
            cin>>thep->the2em[i];
        }
        
        system("pause");
        
        system("cls");
        
        printf("当前2星会员收费分%d段\n",thep->the2fd);
            //2星会员收费分the2fd段 
        for(int i=1;i<=thep->the2fd;i++)
        {
            printf("折扣%d:满%.2f元减%.2f元\n",i,thep->the2j[i],thep->the2em[i]);
        }
        
        system("pause");
        
        set(thep,Customer_number,zhanghao,mima);
    }
    if(thechoice==3)//设置3星会员收费 
    {
        system("cls");
        
        printf("当前3星会员每小时收费%.2f元\n",thep->them3);
        
        printf("新设置3星会员每小时收费");
        
        cin>>thep->them3;
        printf("当前3星会员每小时收费%.2f元\n",thep->them3);
        
        system("pause");
        
        set(thep,Customer_number,zhanghao,mima);
    }
    
    if(thechoice==5)//修改管理员账号
    {
        bool pd=1;
        
        while(pd) 
        {
            string z0,z,zz;
            printf("请输入原管理员账号:");
            cin>>z0; 
            if(zhanghao==z0)
            {
                printf("请输入新管理员账号:");
                cin>>z; 
                
                printf("请再次输入新管理员账号:");
                cin>>zz;
                
                if(z==zz)
                {
                    pd=0;
                    zhanghao=z;
                    
                    system("cls");
                }
                else printf("新账号不一致请重新输入\n");
            }
            else printf("原账号错误请重新输入\n");
        }
        
        printf("设置成功,请重新登陆\n");
        
        system("pause");
        
        set(thep,Customer_number,zhanghao,mima);
    }
    if(thechoice==6)//修改管理员密码
    {
        bool pd=1;
        while(pd) 
        {
            string z0,z,zz;
            
            printf("请输入原管理员密码:");
            cin>>z0; 
            
            if(mima==z0)
            {
                printf("请输入新管理员密码:");
                cin>>z; 
                
                printf("请再次输入新管理员密码:");
                cin>>zz;
                if(z==zz)
                {
                    pd=0;
                    mima=z;
                    system("cls");
                }
                else printf("新密码不一致请重新输入\n");
            }
            else printf("原密码错误请重新输入\n");
        }
        
        printf("设置成功,请重新登陆\n");
        
        system("pause");
        
        set(thep,Customer_number,zhanghao,mima);
    }
    if(thechoice==8)
    {
        for(int i=1;i<=Customer_number;i++)
        {
            printf("第%d位顾客为%d星会员:",i,thep-> line[i].starlevel);
            
            cout <<thep-> line[i].name<<"\n";
            
            cout<<"顾客车牌号为:";
            
            cout<<thep-> line[i].license<<"\n"; 
            
            printf("入库时间为%d年%d月%d日%d时%d分\n"
            ,thep-> line[i].yearin
        ,thep-> line[i].monthin
        ,thep-> line[i].dayin
        ,thep-> line[i].hourin
        ,thep-> line[i].minutein);
        
        printf("出库时间为%d年%d月%d日%d时%d分\n"
        
        ,thep-> line[i].yearout//出库时间 
        ,thep-> line[i].monthout
        ,thep-> line[i].dayout
        ,thep-> line[i].hourout
        ,thep-> line[i].minuteout);
        
        printf("停车时长为%d小时\n",thep-> line[i].the_time);
        
        printf("停车所需金额为%.2f元\n",thep-> line[i].the_money);
        
        }
        system("pause");
    }
    if(thechoice==9)
    {
        set(thep,Customer_number,zhanghao,mima);
    } 
}
void guke(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
        int thechoice;
    printf("输入1显示收费标准\n");
    printf("输入2开始计费\n");
    cin>> thechoice;
    if(thechoice==1)
    {
        printf("1.当前0星会员每小时收费%.2f元\n\n",thep->them0);
        
        printf("2.当前1星会员收费分%d段\n",thep->the1fd);
        for(int i=1;i<=thep->the1fd;i++)
        {
            printf("第%d段收费截止到%d时 每小时收费%.2f元\n",i,thep->the1j[i],thep->the1em[i]);
        }
        printf("\n3.当前2星会员每小时收费%.2f元\n",thep->them2);
            //2星会员每小时收费 them2 元 
        printf("当前2星会员收费分%d段\n",thep->the2fd);
            //2星会员收费分the2fd段 
        for(int i=1;i<=thep->the1fd;i++)
        {
            printf("折扣%d:满%.2f元减%.2f元\n",i,thep->the2j[i],thep->the2em[i]);
        }
        
        printf("\n4.当前3星会员每小时收费%.2f元\n",thep->them3);
        system("pause");
    }
    if(thechoice==2)
    {
        system("pause");
            system("cls");
        Customer_number++;
        cout<<"顾客姓名为:";
        cin>>thep-> line[Customer_number].name; 
        
        cout<<"顾客车牌号为:";
        cin>>thep-> line[Customer_number].license; 
        printf("入库时间为:    年  月  日  时  分");
            
            GotoXY(11,2);
        cin>>thep-> line[Customer_number].yearin;
            GotoXY(17,2);
        cin>>thep-> line[Customer_number].monthin;
            GotoXY(21,2);
        cin>>thep-> line[Customer_number].dayin;
            GotoXY(25,2);
        cin>>thep-> line[Customer_number].hourin;
            GotoXY(29,2);
        cin>>thep-> line[Customer_number].minutein;
        
        
        printf("出库时间为:    年  月  日  时  分");
            
            GotoXY(11,3);
        cin>>thep-> line[Customer_number].yearout;
            GotoXY(17,3);
        cin>>thep-> line[Customer_number].monthout;
            GotoXY(21,3);
        cin>>thep-> line[Customer_number].dayout;
            GotoXY(25,3);
        cin>>thep-> line[Customer_number].hourout;
            GotoXY(29,3);
        cin>>thep-> line[Customer_number].minuteout;
        
        printf("会员星级为:");
        cin>>thep-> line[Customer_number].starlevel;
        
        int the_d;
        
        the_d=dayDis(thep-> line[Customer_number].yearin
        ,thep->line[Customer_number].monthin
        ,thep-> line[Customer_number].dayin
        
        ,thep-> line[Customer_number].yearout
        ,thep-> line[Customer_number].monthout
        ,thep-> line[Customer_number].dayout
        );
        int the_m;
        the_m=(thep-> line[Customer_number].hourout*60+thep-> line[Customer_number].minuteout)
        -(thep-> line[Customer_number].hourin*60+thep-> line[Customer_number].minutein);
        int the_h;
        the_h=the_d*24+the_m/60;
        if(the_m>0&&the_m%60>0)
        {
            the_h++;
        } 
        thep-> line[Customer_number].the_time=the_h;
        printf("停车时长为%d时\n",the_h);
        if(thep-> line[Customer_number].starlevel==0)
            //0星会员收费 
        {
            float sb_money;
            thep-> line[Customer_number].the_money=thep->line[Customer_number].the_time*thep->them0;
            //=sb_money;
            printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
        }
        if(thep-> line[Customer_number].starlevel==1)
            //1星会员收费
        {
        //    thep-> line[Customer_number].the_money=0;
            if(thep->line[Customer_number].the_time>thep->the1j[1])
            {
                thep-> line[Customer_number].the_money+=(thep->the1j[1])*thep->the1em[1];
            }
            else
            {
                thep-> line[Customer_number].the_money+=(thep->line[Customer_number].the_time)*thep->the1em[1];
            }
                
            for(int i=2;i<=thep->the1fd;i++)
            {
                if(thep->line[Customer_number].the_time>thep->the1j[i])
                {
                    thep-> line[Customer_number].the_money+=(thep->the1j[i]-thep->the1j[i-1])*thep->the1em[i];
                }
                else
                {
                    thep-> line[Customer_number].the_money+=(thep->line[Customer_number].the_time-thep->the1j[i])*thep->the1em[i];
                }
            } 
            printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
        }
        if(thep-> line[Customer_number].starlevel==2)
            //2星会员收费
        {
            thep-> line[Customer_number].the_money=thep->line[Customer_number].the_time*thep->them2;
            for(int i=thep->the1fd;i>=1;i--)
            {
                if(thep->line[Customer_number].the_money>thep->the2j[i])
                {
                    thep-> line[Customer_number].the_money-=thep->the2em[i];
                    break;
                }
            } 
            printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
        }
        if(thep-> line[Customer_number].starlevel==3)
            //3星会员收费 
        {
            float sb_money;
            thep-> line[Customer_number].the_money=thep->line[Customer_number].the_time*thep->them3;
            //=sb_money;
            printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
        }
        
        system("pause");
        
        set(thep,Customer_number,zhanghao,mima);
    }
}
void set(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    while(1)
    {
        //system("pause");
        system("cls");
        printf("输入1登录管理系统,输入2登录顾客系统\n");
        
        int dengluxuanxiang;
        cin>>dengluxuanxiang;
        
        if(dengluxuanxiang==1)
        {
            printf("请输入赵名扬设置的管理员账号:");
            
            string x;
            cin>>x;
            
            printf("请输入赵名扬设置的管理员密码:");
            
            string y;
            cin>>y;
            
            if(x!=zhanghao
            ||y!=mima)
            
            {
                printf("账号或密码错误请重新登录"); 
                system("pause");
                set(thep,Customer_number,zhanghao,mima);
            }
            printf("登录成功");
            
            system("pause");
            
            system("cls");
            
            guanli(thep,Customer_number,zhanghao,mima);
        }
        else if(dengluxuanxiang==2)
        {
            system("pause");
            
            system("cls");
            
            guke(thep,Customer_number,zhanghao,mima);
        }
        else
        {
            printf("错误请重新登录"); 
            
            system("pause");
            
            set(thep,Customer_number,zhanghao,mima);
        }
    }
}
void newset(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    thep->line[0].name = "赵名扬";        //顾客姓名
    
    thep->line[0].license="皖K209L1";     //顾客车牌号 
    
        thep->line[0].yearin=1;            //入库时间 
        thep->line[0].monthin=1;
        thep->line[0].dayin=1;
        thep->line[0].hourin=1;
        thep->line[0].minutein=1;
        
        thep->line[0].yearout=1;        //出库时间 
        thep->line[0].monthout=1;
        thep->line[0].dayout=1;
        thep->line[0].hourout=1;
        thep->line[0].minuteout=1;
        
        thep->line[0].starlevel=1;
        
        thep->them0=1;        //默认设置 
                            //0星会员每小时收费 1 元 
        
        thep->the1fd=1;        //1星会员收费分the1fd段 
        thep->the1j[1]=99;    //1星会员收费每段收费截止到 99时 
        thep->the1em[1]=1;    //1星会员每段每小时收费 1 元 
        
        thep->them2=1;        //2星会员每小时收费 them2 元 
        thep->the2fd=1;        //2星会员收费分the2fd段 
        thep->the2j[1]=1;    //2星会员收费每段收费截止到 1时 
        thep->the2em[1]=1;    //2星会员每段满减为 1元
        
        thep->them3=0.9;        //3星会员每小时收费 0.9 元 
        
        set(thep,Customer_number,zhanghao,mima);
}
float money0(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    
    float money;
    
    money=thep->line[Customer_number].the_time*thep->them0;
    
    thep-> line[Customer_number].the_money=money;
    
    return money;
}
float money1(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    
    float money=0;
    
            if(thep->line[Customer_number].the_time>thep->the1j[1])
            {
                money+=(thep->the1j[1])*thep->the1em[1];
            }
            else
            {
                money+=(thep->line[Customer_number].the_time)*thep->the1em[1];
            }
                
            for(int i=2;i<=thep->the1fd;i++)
            {
                if(thep->line[Customer_number].the_time>thep->the1j[i])
                {
                    money+=(thep->the1j[i]-thep->the1j[i-1])*thep->the1em[i];
                }
                else
                {
                    money+=(thep->line[Customer_number].the_time-thep->the1j[i])*thep->the1em[i];
                }
            } 
            //printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
            
        return money;
}
float money2(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    float money=0;
    
            money=thep->line[Customer_number].the_time*thep->them2;
            for(int i=thep->the1fd;i>=1;i--)
            {
                if(money>thep->the2j[i])
                {
                    money-=thep->the2em[i];
                    break;
                }
            } 
            //printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
            
    return money;
}
float money3(allcustomer *thep,int Customer_number,string zhanghao,string mima)
{
    float money=0;
    
            money=thep->line[Customer_number].the_time*thep->them3;
        //    printf("停车所需金额为为%.2f元\n",thep-> line[Customer_number].the_money);
        
    return money;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值