迟来的深情比草都贱系列——命苦的期中考试

考试题目大概是设计一个餐厅订单系统

需要设计菜单类和订单类

然后输入三个数字分别代表菜单食品的数量,不可食用食品数量以及顾客想要的食品数量

驻波考试辛辛苦苦坐了一个小时,结果编译错误,因为不知道如何不创建对象直接在类外使用类内函数,修改了千八百遍还是不行,最终无奈放弃,丢失二十分

回到宿舍一问豆老师才知道,函数前面加上static或许可行,于是便复现考试时的代码,谁曾想真的可行,驻波心里好苦呀。。。。

#include
using namespace std;

int n,m,o;
vectorcannoteat;

class Menu
{
    public:
    static mapfood;
    static bool isCanDesipote(string n);
    Menu(){};
    ~Menu(){};
};

class Desipote
{
    private:
    friend class Menu;
    static double amount;
    static vectorlis;

    public:
    static void add(string n);
    static void calculate();
    static void display();
    Desipote(){};
    ~Desipote(){};
};

map Menu::food;
double Desipote::amount = 0.0;
vector Desipote::lis;

bool Menu::isCanDesipote(string n)
{
    for(const auto& no : cannoteat)
    {
        if(n==no)
        return false;
    }
    return true;
}

void Desipote::add(string n)
{
    lis.push_back(n);
}

void Desipote::calculate()
{
    for(const auto& l: lis)
    {
        amount+=Menu::food[l];
    }
}

void Desipote::display()
{
    cout<>n>>m>>o;

    for(int i=0;i>name>>price;
        Menu::food[name]=price;
    }

    for(int i=0;i>cannoteatname;
        cannoteat.push_back(cannoteatname);
    }

    for(int i=0;i>wanna;
        if(Menu::isCanDesipote(wanna))
        {
            Desipote::add(wanna);
        }
    }

    Desipote::calculate();
    Desipote::display();

    return 0;
}

你可能感兴趣的:(c++,期中考试)