Problem32工厂模式、makefile、别拼错单词

2020-08-19

知识点

工厂模式

对于每一种产品都对应一种工厂类。

class Factory {
public:
    virtual Pizza* make_pizza(string name, int ketchup, int cheess) = 0;
};

class Factory_not_cut: public Factory {
public:
    virtual Pizza* make_pizza(string name, int ketchup, int cheese){
        Plate *plate = find_empty_plate();
        if (plate == nullptr) return nullptr;
        Pizza *pizza = new Pizza(name, ketchup, cheese);
        pizza->cook();
        pizza->put_on(plate);
        return pizza;
    }
};

class Factory_beef: public Factory_not_cut {
public:
    virtual Pizza* make_pizza(){
        return Factory_not_cut::make_pizza("Beef Pizza", 20, 40);
    }
};

class Factory_fruit: public Factory_not_cut {
public:
    virtual Pizza* make_pizza(){
        return Factory_not_cut::make_pizza("Fruit Pizza", 0, 0);
    }
};

class Factory_tomato: public Factory_not_cut {
public:
    virtual Pizza* make_pizza(){
        return Factory_not_cut::make_pizza("Tomato Pizza", 20, 0);
    }
};

class Factory_cut: public Factory {
public:
    virtual Pizza* make_pizza(string name, int ketchup, int cheese){
        Plate *plate = find_empty_plate();
        if (plate == nullptr) return nullptr;
        Pizza *pizza = new Pizza(name, ketchup, cheese);
        pizza->cook();
        pizza->cut();
        pizza->put_on(plate);
        return pizza;
    }
};

class Factory_seafood: public Factory_cut {
public:
    virtual Pizza* make_pizza(){
        return Factory_cut::make_pizza("Seafood Pizza", 30, 90);
    }
};

class Factory_sausage: public Factory_cut {
public:
    virtual Pizza* make_pizza(){
        return Factory_cut::make_pizza("Sausage Pizza", 40, 20);
    }
};

class Factory_cheese: public Factory_cut {
public:
    virtual Pizza* make_pizza(){
        return Factory_cut::make_pizza("Cheese Pizza", 0, 20);
    }
};

makefile模板

快速编写makefile。修改以下模板即可。

main:main.o Student.o StudentManager.o Birthday.o StudentManager.h Student.h Birthday.h
    g++ main.o Student.o StudentManager.o Birthday.o -o main

Student.o:Student.cpp Student.h Birthday.h
    g++ -c Student.cpp -o Student.o

Birthday.o:Birthday.cpp Birthday.h
    g++ -c Birthday.cpp -o Birthday.o

StudentManager.o:StudentManager.cpp Student.h Birthday.h StudentManager.h
    g++ -c StudentManager.cpp -o StudentManager.o

main.o:main.cpp StudentManager.h Student.h Birthday.h
    g++ -c main.cpp -o main.o

clean:
    rm main *.o

带flag的makefile

# THUOOP @ 20200129
# C++ Course for THU2020 on Linux
#
.PHONY:clean
FLAG=$(empty) $(empty)
all:main
main:main.o product.o sum.o functions.h
    g++ main.o product.o sum.o -o main

product.o:product.cpp functions.h
    g++ -c ${FLAG} product.cpp -o product.o

sum.o:sum.cpp functions.h
    g++ -c ${FLAG} sum.cpp -o sum.o

main.o:main.cpp functions.h
    g++ -c ${FLAG} main.cpp -o main.o

clean:
    rm main *.o

别拼错单词!

啊这,由于拼错单词而过不了评测也不是没有发生过orz

你可能感兴趣的:(Problem32工厂模式、makefile、别拼错单词)