• 实验六


    #include <bits/stdc++.h>
    using namespace std;
    const int MAX_num_AIM = 3;
    const int MAX_num_TRAVELWAY = 2;
    const int MAX_num_LUGGAGENUMBER = 3;
    const int MAX_num_PASSENGER = 62;
    enum Aim {DomesticShort, DomesticLong, International};
    enum TravelWay {Free, Agency};
    class Luggage{
    public:
        void nameself(string name,int luggageNumber);
        int number;
        string name[3];
    };
    class Passenger{
    public:
        Passenger(string name,int luggageNumber, TravelWay travelWay, Aim aim);
        void Introduce();
        string name;
        Luggage luggage;
        TravelWay travelWay;
        Aim aim;
        int money;
        int carryMoney;
    };
    string passengername[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"};
    int ticket(int luggageNumber, Aim aim);
    class Team{
    public:
        Aim aim;
        string name;
        int number;
        int money;
    };
    class TravelAgency{
    public:
        void regist(Passenger &passenger);
        Team team[5];
        int number;
        void introduce(void);
    };
    TravelAgency travelAgency;
    class TicketOffice{
    public:
        void regist(Passenger &passenger);
        void regist(TravelAgency &travelAgency);
        void introduce(void);
        int money[6];
        string name[6];
    };
    TicketOffice ticketOffice;
    int main(){
        ios::sync_with_stdio(false);
        srand(static_cast<unsigned> (time(NULL)));
        int passengerNumber = rand() % MAX_num_PASSENGER;
        for (int i = 0; i < passengerNumber; i++){
            Passenger passenger(passengername[i], 1 + rand() % MAX_num_LUGGAGENUMBER, (TravelWay) (rand() % MAX_num_TRAVELWAY), (Aim) (rand() % MAX_num_AIM));
            travelAgency.regist(passenger);
            ticketOffice.regist(passenger);
        }
        ticketOffice.regist(travelAgency);
        travelAgency.introduce();
        ticketOffice.introduce();
        cout << endl;
        return 0;
    }
    Passenger::Passenger(string name,int luggageNumber, TravelWay travelWay, Aim aim){
        this->name = name;
        this->luggage.number = luggageNumber;
        this->luggage.nameself(name, luggageNumber);
        this->travelWay = travelWay;
        this->aim = aim;
        this->money = ticket(luggageNumber, aim);
        if (aim == International && this->luggage.number > 2)   this->carryMoney = 100;
        else    this->carryMoney = 0;
        Introduce();
    }
    void Passenger::Introduce(){
        cout << "    我是乘客 " << name << ",";
        if (travelWay == Free)  cout << "选择自由出行";
        else    cout << "报名旅行社";
        cout << ",";
        if (aim == DomesticShort)   cout << "选择国内短途";
        if (aim == DomesticLong)    cout << "选择国内长途";
        if (aim == International)   cout << "选择国际游";
        cout << ",携带" << this->luggage.number << "件行李,行李编号是 ";
        for (int i = 0; i < this->luggage.number; i++){
            if (i != 0)     cout << "、";
            cout << this->luggage.name[i];
        }
        cout << ",买票需付" << money << "元";
        if (carryMoney)     cout << ",行李托运费100元";
        cout << "。" << endl;
    }
    void TravelAgency::regist(Passenger &passenger){
        if (passenger.travelWay != Agency)  return;
        for (int i = 0; i < 5; i++){
            if (travelAgency.team[i].number == 0){
                travelAgency.team[i].name += passenger.name;
                travelAgency.number++;
                travelAgency.team[i].number++;
                travelAgency.team[i].aim = passenger.aim;
                travelAgency.team[i].money += passenger.money + passenger.carryMoney;
                break;
            }
            else if (travelAgency.team[i].aim == passenger.aim && travelAgency.team[i].number < 6){
                travelAgency.team[i].name = travelAgency.team[i].name + "," + passenger.name;
                travelAgency.number++;
                travelAgency.team[i].money += passenger.money + passenger.carryMoney;
                travelAgency.team[i].number++;
                break;
            }
        }
    }
    int ticket(int luggageNumber, Aim aim){
        int money = 0;
        if (aim == DomesticShort)   money += 10;
        if (aim == DomesticLong)    money += 100;
        if (aim == International)   money += 500;
        return money;
    }
    void Luggage::nameself(string name,int luggageNumber){
        char str[2];
        for (int i = 0; i < luggageNumber; i++){
            sprintf(str, "%d", i + 1);
            this->name[i] = name + "0" + str;
        }
    }
    void TravelAgency::introduce(void){
        cout << "    旅行社开始报名。" << endl << "    旅行社共计安排了5个旅行团,共计" << number << "人报名。" << endl << "出行的目的地分别是:";
        for (int i = 0; i < 5; i++){
            switch (team[i].aim){
            case DomesticShort:
                if (team[i].number != 0)    cout << "国内短途";
                else {
                    int temp =  rand() % 3;
                    switch (temp) {
                        case 0: cout << "国内短途"; break;
                        case 1: cout << "国内长途"; break;
                        case 2: cout << "国际游";  break;
                    }
                }
                break;
            case DomesticLong:  cout << "国内长途"; break;
            case International: cout << "国际游";  break;
            }
            if (i < 4)  cout << ",";
            else    cout << ";";
        }
        cout << "每个旅行团的人数分别是:";
        for (int i = 0; i < 5; i++) {
            cout << team[i].number;
            if (i < 4)  cout << ",";
            else    cout << ";";
        }
        cout << "每个旅行团需要支付的票价是:";
        for (int i = 0; i < 5; i++) {
            cout << team[i].money;
            if (i < 4)  cout << ",";
            else    cout << "。" << endl;
        }
    }
    void init(int &num) {
        cout << ticketOffice.money[num];
        cout << "元,乘客姓名:";
        cout << ticketOffice.name[num++];
    }
    void TicketOffice::introduce(void){
        int num = 0;
        cout << "    售票处开始售票。" << endl << "    售票结束,营业额统计信息如下:";
        cout << endl << "    国内短途自由行:";    init(num);
        cout << endl << "    国内长途自由行:";    init(num);
        cout << endl << "    国际游自由行:  ";    init(num);
        cout << endl << "    国内短途团购:  ";    init(num);
        cout << endl << "    国内长途团购:  ";    init(num);
        cout << endl << "    国际游团购:    ";    init(num);
    }
    void TicketOffice::regist(Passenger &passenger){
        if (passenger.travelWay != Free)    return;
        int num = passenger.aim;
        if (money[num] != 0)    name[num] += ",";
        name[num] += passenger.name;
        money[num] += passenger.money + passenger.carryMoney;
    }
    void TicketOffice::regist(TravelAgency &travelAgency){
        for (int i = 0, num; i < 5; i++){
            if (travelAgency.team[i].number == 0)   continue;
            num = 3 + travelAgency.team[i].aim;
            if (money[num] != 0)    name[num] += ",";
            name[num] += travelAgency.team[i].name;
            money[num] += travelAgency.team[i].money;
        }
    }
    
        //                  //
        //      \         //
        //       \       //
        // ##DDDDDDDDDDDDDDDDDDDDDD##
        // ## DDDDDDDDDDDDDDDDDDDD ##   ________   ___   ___        ___   ________   ___   ___        ___
        // ## hh                hh ##   |   __   |   |        |   |   __   |   |        |  
        // ## hh    //    \    hh ##      | /_   \           \   | /_   \           
        // ## hh   //      \   hh ##        __  \   \           \    __  \   \           
        // ## hh                hh ##        |  \   \   \____    \   |  \   \   \____    
        // ## hh      wwww      hh ##       \_______\ \__\ \_______\ \__\ \_______\ \__\ \_______\ \__
        // ## hh                hh ##       |_______| |__| |_______| |__| |_______| |__| |_______| |__|
        // ## MMMMMMMMMMMMMMMMMMMM ##
        // ##MMMMMMMMMMMMMMMMMMMMMM##
        //      /            /
    
    作者:LightAc
    出处:https://www.cnblogs.com/lightac/
    联系:
    Email: dzz@stu.ouc.edu.cn
    QQ: 1171613053
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    查找链表中是否有环linked-list-cycle
    reverse-integer
    AVL树之 Java的实现
    single-number
    Best Time to Buy and Sell Stock II
    maximun-depth-of-binary-tree
    minimun-depth-of-binary-tree
    剑指offer--矩阵中的路径
    grep的几个参数
    fsck和badlocks
  • 原文地址:https://www.cnblogs.com/lightac/p/10809549.html
Copyright © 2020-2023  润新知