📄 dog.cc
字号:
#include <iostream>using namespace std;enum BREED { GOLDEN, CAIRN, DANDIE, SHETLAND, DOBERMAN, LAB };class Mammal{protected: int itsAge; int itsWeight;public: // constructors Mammal():itsAge(0),itsWeight(100) { cout << "Mammal()" << endl; } ~Mammal() { cout << "~Mammal()" << endl; } //accessors int GetAge() const { return itsAge; } void SetAge(int a) { itsAge = a; } int GetWeight() const { return itsWeight; } void SetWeight( int w ) { itsWeight = w; } //Other methods void Speak() const { cout << "Mammal speak" << endl; } void Sleep() const { cout << "Mammal sleep" << endl; }};class Dog : public Mammal{protected: BREED itsBreed;public: // Constructors Dog():itsBreed(LAB) { // itsAge = 0; // itsWeight = 100; cout << "Dog()" << endl; } ~Dog() { cout << "~Dog()" << endl; } // Accessors BREED GetBreed() const { return itsBreed; } void SetBreed(BREED b) { itsBreed = b; } // Other methods void WagTail() { cout << "Dog wags tail" << endl; } void BegForFood() { cout << "Dog begs for food" << endl; }};int main(){ Dog od; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -