⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 C++ Source code from a tutorial
💻 CPP
字号:
#include <iostream>
#include <stdlib.h>

using namespace std;

class FrozenFood {
private:
    int Price;
protected:
    int Weight;
public:
    FrozenFood(int APrice, int AWeight);
    int GetPrice();
    int GetWeight();
    virtual void BakeChemistry() = 0;
};

class FrozenPizza : public FrozenFood {
protected:
    int Diameter;
public:
    FrozenPizza(int APrice, int AWeight, int ADiameter);
    void DumpInfo();
    void BakeChemistry();
};

class DeepDishPizza : public FrozenPizza {
private:
    int Height;
public:
    DeepDishPizza(int APrice, int AWeight, int ADiameter, int AHeight);
    void DumpDensity();
};


FrozenFood::FrozenFood(int APrice, int AWeight) { 
    Price = APrice; 
    Weight = AWeight;
}

int FrozenFood::GetPrice() {
    return Price;
}

int FrozenFood::GetWeight() {
    return Weight;
}

void FrozenFood::BakeChemistry() {
    cout << "Baking, baking, baking!" << endl;
}

FrozenPizza::FrozenPizza(int APrice, int AWeight, int ADiameter) :
FrozenFood(APrice, AWeight) {
    Diameter = ADiameter;
}

void FrozenPizza::DumpInfo() {
    cout << "\tFrozen pizza info:" << endl;
    cout << "\t\tWeight: " << Weight << " ounces" << endl;
    cout << "\t\tDiameter: " << Diameter << " inches" << endl;
}

void FrozenPizza::BakeChemistry() {
    cout << "I'm getting crispy!" << endl;
}


DeepDishPizza::DeepDishPizza(int APrice, int AWeight, 
int ADiameter, int AHeight) :
FrozenPizza(APrice, AWeight, ADiameter) {
    Height = AHeight;
}

void DeepDishPizza::DumpDensity() {
    // Calculate pounds per cubic foot of deep dish pizza
    cout << "\tDensity: ";
    cout << Weight * 12 * 12 * 12 * 14 / (Height * Diameter * 22 * 16);
    cout << " pounds per cubic foot" << endl;
}

void Bake(FrozenFood *) {
    cout << "Baking" << endl;
}

int main(int argc, char *argv[])
{
    cout << "Thin crust pepperoni" << endl;
    FrozenPizza pepperoni(450, 12, 14);
    pepperoni.DumpInfo();
    cout << "\tPrice: " << pepperoni.GetPrice() << " cents" << endl;
    pepperoni.BakeChemistry();
    
    cout << "Deep dish extra-cheese" << endl;
    DeepDishPizza extracheese(650, 21592, 14, 3);
    extracheese.DumpInfo();
    extracheese.DumpDensity();
    cout << "\tPrice: " << extracheese.GetPrice() << " cents" << endl;
    
    Bake(&extracheese);
    
    system("PAUSE");
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -