八云墨玄 2021-06-28 15:31 采纳率: 71.4%
浏览 304
已采纳

希望能有一位很懂c语言的能设计一下我的课设程序,用c语言,汽车租赁管理系统

希望能包含图片中的功能,且能给每一个顾客编号,车辆编车牌号,能通过顾客编号查询他的租车信息。

能设置两种车型(轿车和客车),租车时需要输入一些必要的信息且在查询时能显示。

最后拜托多点注释!多点注释!谢谢大佬的帮助

 

  • 写回答

5条回答 默认 最新

  • qfl_sdu 2021-06-30 15:23
    关注

    代码如下:如有帮助,请采纳一下,谢谢。

    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    #include <process.h>
    //定义汽车类型
    enum ECarType
    {
        e_car_jc=1,
        e_car_kc
    };
    //定义汽车类
    class Car 
    {
    private:
        char mId[10];   //汽车编号
        enum ECarType mType; //汽车类型
        int mPriceDay;  //日租价格
        int mPriceMon;  //月租价格
        int mPriceYear; //年租价格
        //还可以添加颜色、品牌等等属性,这里就不加了,有兴趣自己添加就可以了
    public:
        Car(){}
        Car(char* id,enum ECarType e,int d,int m,int y)
        {
            strcpy(mId,id);
            mType = e;
            mPriceDay = d;
            mPriceMon = m;
            mPriceYear = y;
        };
    
        char* getId(){return mId;}
        enum ECarType getType(){return mType;}
        int getDayprice(){return mPriceDay;}
        int getMonprice(){return mPriceMon;}
        int getYearprice(){return mPriceYear;}
    
        void setId(char* p){strcpy(mId,p);}
        void setType(enum ECarType e){mType = e;}
        void setPrice(int d,int m,int y)
        {
            mPriceDay = d;
            mPriceMon = m;    
            mPriceYear = y;
        };
    
    
    
    };
    
    //定义租赁人信息
    class Guest 
    {
    private:
        char mId[20];   //租客编号
        char mName[20]; //租客姓名 
        char mPhone[12];//租客电话
    public:
        Guest(){}
        Guest(char* id,char* name,char* phone)
        {
            strcpy(mId,id);
            strcpy(mName,name);
            strcpy(mPhone,phone);
        }
        char* getId(){return mId;}
        char* getName(){return mName;}
        char* getPhone(){return mPhone;}
    
        void setId(char* id){strcpy(mId,id);}
        void setName(char* name){strcpy(mName,name);}
        void setPhone(char* phone){strcpy(mPhone,phone);}
    };
    //定义日期类
    struct Date 
    {
        int year;
        int month;
        int day;
    };
    
    //租赁方式:日租、月租、年租
    /*enum EUseType
    {
        e_use_day=1,
        e_use_month,
        e_use_year
    };*/
    
    
    //租赁信息
    struct UseInfo 
    {
        class Car* pCar;   //汽车实例
        class Guest* guest;//当前汽车租赁人
        struct Date date;  //租赁日期
        //enum EUseType type;//租赁方式
    
        void show()
        {
            printf("车辆编号:%s\n",pCar->getId());
            if(pCar->getType() == e_car_jc)
                printf("车辆类型:轿车\n");
            else
                printf("车辆类型:客车\n");
            if(guest == 0)
            {
                printf("车辆状态:未出租\n");
            }
            else
            {
                printf("车辆状态:已出租\n");
                /*if (type == e_use_day)
                    printf("出租方式:日租\n");
                else if(type == e_use_month)
                    printf("出租方式:月租\n");
                else
                    printf("出租方式:年租\n");*/
                printf("出租日期:%d年%d月%d日\n",date.year,date.month,date.day);
            }
            
        }
    };
    
    //获取当前时间
    Date GetCurTime()
    {
        time_t timep;
        struct tm *p;
        Date dd;
        time(&timep);
        p = gmtime(&timep);
        dd.year = 1900 + p->tm_year;
        dd.month = 1+p->tm_mon;
        dd.day = p->tm_mday;
        return dd;
    }
    //计算两个日期间的年、月、日
    void Caculate(Date start,Date end,int *year,int *mon,int* day)
    {
        int ds[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        *year = end.year - start.year;
        if (end.month < start.month)
        {
            *year = *year -1;
            *mon = end.month + 12 - start.month;
        }else
        {
            *mon = end.month - start.month;
        }
    
        if (end.day < start.day)
        {
            *mon = *mon -1;
            *day = end.day + ds[start.month] - start.day;
        }else
        {
            *day = end.day - start.day;
        }
    }
    
    //添加汽车信息
    void AddNewCar(class Car* cars[],int* nmb,struct UseInfo useinfo[],int *nmbInfo)
    {
        int bgo = 1;
        char mId[10];   //汽车编号
        int type;       //汽车类型
        int mPriceDay;  //日租价格
        int mPriceMon;  //月租价格
        int mPriceYear; //年租价格
        char ch;
        class Car* pcar = 0;
        while(bgo)
        {
            system("cls");
            printf("请输入汽车编号:");
            scanf("%s",mId);
            printf("请输入汽车类型(1.轿车 2.客车)");
            scanf("%d",&type);
            printf("请输入日租价格、月租价格和年租价格,以空格分隔:");
            scanf("%d %d %d",&mPriceDay,&mPriceMon,&mPriceYear);
            pcar = new Car();
            pcar->setId(mId);
            if(type == 1)
                pcar->setType(e_car_jc);
            else
                pcar->setType(e_car_kc);
            pcar->setPrice(mPriceDay,mPriceMon,mPriceYear);
    
            cars[*nmb] = pcar;
            *nmb = *nmb + 1;
    
            //将汽车添加到租赁服务中
            useinfo[*nmbInfo].pCar = pcar;
            useinfo[*nmbInfo].guest = 0; //表示没有被租赁
            *nmbInfo = *nmbInfo + 1;
    
    
    
            printf("是否继续添加(y/n)?");
            while(1)
            {
                scanf(" %c",&ch);
                getchar();
                if(ch == 'y' || ch == 'Y')
                    break;
                else if(ch =='n'||ch == 'N')
                {
                    bgo = false;
                    break;
                }
            }
        }
        system("pause");
    }
    
    //判断租车人是否存在,如果存在返回顾客实例指针,否则返回0
    class Guest* isExist(char* id,class Guest* guest[],int nmbGuest)
    {
        int i;
        for (i=0;i< nmbGuest;i++)
        {
            if(strcmp(guest[i]->getId(),id)==0)
                return guest[i];
        }
        return 0;
    }
    
    //根据条件获取可用的车辆
    class Car* getUsefullCar(struct UseInfo useinfo[],int nmbInfo,ECarType ecar,int *index)
    {
        int i;
        for (i=0;i<nmbInfo;i++)
        {
            if (useinfo[i].guest == 0 && useinfo[i].pCar != 0 && useinfo[i].pCar->getType() == ecar)
            {
                *index = i;
                return useinfo[i].pCar;
            }
        }
        return 0;
    }
    
    
    //汽车租赁
    void UseCar(struct UseInfo useinfo[],int nmbInfo,class Guest* guest[],int *nmbGuest)
    {
        char name[20]={0};
        char id[20]={0};
        char phone[20]={0};
        int type;
        int mode;
        Guest* gu = 0;
        Car* pcar = 0;
        ECarType eCar;
        //EUseType eUse;
        int index = 0;
        
        int y,m,d;
    
        system("cls");
        printf("请输入租车人的编号:");
        scanf("%s",id);
        printf("请输入租车人的姓名:") ;
        scanf("%s",name);
        printf("请输入租车人的电话:");
        scanf("%s",phone);
    
        gu = isExist(id,guest,*nmbGuest);
        if(gu == 0)
        {
            gu = new Guest(id,name,phone);
            guest[*nmbGuest] = gu;
            *nmbGuest = *nmbGuest + 1;
        }
        //
        printf("请输入租车类型:1.轿车 2.客车:");
        scanf("%d",&type);
        //printf("请输入租车方式:1.日租 2.月租 3.年租:");
        //scanf("%d",&mode);
        printf("请输入起租日期:");
        scanf("%d %d %d",&y,&m,&d);
    
    
        if(type == 1)
            eCar = e_car_jc;
        else
            eCar = e_car_kc;
        /*if(mode == 1)
            eUse = e_use_day;
        else if(mode == 2)
            eUse = e_use_month;
        else
            eUse = e_use_year;*/
    
        pcar = getUsefullCar(useinfo,nmbInfo,eCar,&index);
        if(pcar == 0)
            printf("当前已无该类型的车辆可以出租\n");
        else
        {
            useinfo[index].guest = gu;
            /*if(1==mode)
                useinfo[index].type = e_use_day;
            else if(2== mode)
                useinfo[index].type = e_use_month;
            else
                useinfo[index].type = e_use_year;*/
            useinfo[index].date.year = y;
            useinfo[index].date.month = m;
            useinfo[index].date.day = d;
            printf("租车成功,车辆编号:%s\n",pcar->getId());
        }
    
        system("pause");
    }
    
    
    //汽车信息查询
    void FindCar(struct UseInfo useinfo[],int nmbInfo)
    {
        char id[20]={0};
        int type;
        int opt,i;
        int isfind ;
        int bgo = 1;
        char ch;
        while(bgo)
        {
            system("cls");
            printf("1.根据编号查询\n");
            printf("2.根据类型查询\n");
            printf("3.查询已出租车辆\n");
            printf("4.查询未出租车辆\n");
            printf("5.显示全部车辆\n");
            scanf("%d",&opt);
            switch(opt)
            {
            case 1:
                printf("请输入编号");
                scanf("%s",id);
                for (i=0;i<nmbInfo;i++)
                {
                    if (strcmp(id,useinfo[i].pCar->getId()) == 0)
                    {
                        useinfo[i].show();
                        break;
                    }
                }
                if(i == nmbInfo)
                    printf("未找到编号为%s的车辆\n",id);
                break;
            case 2:
                printf("请输入类型(1.轿车 2.客车):");
                scanf("%d",&type);
                isfind = 0;
                for (i=0;i<nmbInfo;i++)
                {
                    if ( useinfo[i].pCar->getType() == type)
                    {
                        useinfo[i].show();
                        isfind = 1;
                    }
                }
                if(0== isfind)
                    printf("未找到该类型的车辆\n");
                break;
            case 3:
                isfind = 0;
                for (i=0;i<nmbInfo;i++)
                {
                    if ( useinfo[i].guest != 0)
                    {
                        useinfo[i].show();
                        isfind = 1;
                    }
                }
                if(0== isfind)
                    printf("未找到符合要求的车辆\n");
                break;
            case 4:
                isfind = 0;
                for (i=0;i<nmbInfo;i++)
                {
                    if ( useinfo[i].guest == 0)
                    {
                        useinfo[i].show();
                        isfind = 1;
                    }
                }
                if(0== isfind)
                    printf("未找到符合要求的车辆\n");
                break;
            case 5:
                for (i=0;i<nmbInfo;i++)
                {
                    useinfo[i].show();
                }
                break;
            }
    
            printf("是否继续查询(Y/N)?");
            while(1)
            {
                scanf(" %c",&ch);
                getchar();
                if(ch == 'y' || ch == 'Y')
                    break;
                else if(ch =='n'||ch == 'N')
                {
                    bgo = false;
                    break;
                }
            }
        }
        system("pause");
    }
    
    //查询用户信息
    void FindUser(struct UseInfo useinfo[],int nmbInfo,class Guest* guest[],int nmbGueset)
    {
        char tmp[20]={0};
        int i;
        int bgo = 1;
        int bfind = 0;
        Guest* pguest = 0;
        char ch;
        while(bgo)
        {
            system("cls");
            memset(tmp,0,20);
            bfind = 0;
            printf("请输入需要查询的用户编号或者姓名或者电话:");
            scanf("%s",tmp);
            pguest = 0;
            for (i=0;i<nmbGueset;i++)
            {
                if (strcmp(guest[i]->getId(),tmp)==0 || strcmp(guest[i]->getName(),tmp)==0 || strcmp(guest[i]->getPhone(),tmp)==0  )
                {
                    pguest = guest[i];
                }
            }
            
            if (pguest == 0)
            {
                printf("未找到该用户\n");
            }else
            {
                printf("用户编号:%s\n",pguest->getId());
                printf("用户姓名:%s\n",pguest->getName());
                printf("用户电话:%s\n",pguest->getPhone());
                for (i=0;i<nmbInfo;i++)
                {
                    if(useinfo[i].guest == pguest )
                    {
                        useinfo[i].show();
                        break;
                    }
                }
            }
    
            printf("是否继续查询(y/n)?");
            while(1)
            {
                scanf(" %c",&ch);
                getchar();
                if(ch == 'y' || ch == 'Y')
                    break;
                else if(ch =='n'||ch == 'N')
                {
                    bgo = false;
                    break;
                }
            }
    
            
        }
    }
    
    //汽车归还
    void CarBack(struct UseInfo useinfo[],int nmbInfo)
    {
        char id[20]={0};
        int i;
        Date cur;
        int year,mont,day;
        int price = 0;
        system("cls");
        printf("请输入归还车辆的编号:");
        scanf("%s",id);
        for (i=0;i<nmbInfo;i++)
        {
            if (strcmp(id,useinfo[i].pCar->getId()) == 0 )
            {
                if(useinfo[i].guest != 0)
                {
                    //计算应付金额
                    cur = GetCurTime();
                    Caculate(useinfo[i].date,cur,&year,&mont,&day);
                    printf("起租时间:%d年%d月%d天\n",useinfo[i].date.year,useinfo[i].date.month,useinfo[i].date.day);
                    printf("还车时间:%d年%d月%d天\n",cur.year,cur.month,cur.day);
                    printf("租借时长:%d年%d月%d天\n",year,mont,day);
                    price = year * useinfo[i].pCar->getYearprice() + mont*useinfo[i].pCar->getMonprice() + day * useinfo[i].pCar->getDayprice();
                    printf("应缴金额:%d\n",price);
                    useinfo[i].guest = 0;
                }else
                    printf("该车辆尚未出租\n");
                
                break;
            }
        }
        if (i==nmbInfo)
        {
            printf("未找到该编号的车辆\n");
        }
        system("pause");
    }
    
    int main()
    {
        struct UseInfo useinfo[50];   //保存租赁信息
        int nmbZl = 0;                //实际租赁信息条数
        class Car* cars[50];    //保存汽车信息
        int nmbCars = 0;        //实际有的汽车数量
        class Guest* guest[50]; //保存顾客信息
        int nmbGuest = 0;       //实际顾客数量
        int bgo = 1;            //系统运行标识
        int opt;
        while(bgo)
        {
            system("cls");
            printf("----------------汽车租赁管理系统-----------------\n");
            printf("|    1.录入汽车信息                             |\n");
            printf("|    2.汽车租赁                                 |\n");
            printf("|    3.汽车信息查询                             |\n");
            printf("|    4.顾客信息查询                             |\n");
            printf("|    5.车辆归还                                 |\n");//在归还时计算费用
            printf("|    0.退出系统                                 |\n");
            printf("-------------------------------------------------\n");
            
            scanf("%d",&opt);
            switch(opt)
            {
            case 0:
                bgo = 0;
                break;
            case 1:
                AddNewCar(cars,&nmbCars,useinfo,&nmbZl);
                break;
            case 2:
                UseCar(useinfo,nmbZl,guest,&nmbGuest);
                break;
            case 3:
                FindCar(useinfo,nmbZl);
                break;
            case 4:
                FindUser(useinfo,nmbZl,guest,nmbGuest);
                break;
            case 5:
                CarBack(useinfo,nmbZl);
                break;
            }
        }
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效