1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include<iostream> using namespace std;
class Human {
public: void get_stature() {cout << stature << endl;} void GetWeight(); void SetStature(int x) {stature = x;} void SetWeight(int x); private: int stature; int weight;
};
void Human::GetWeight() { cout<<weight; } void Human::SetWeight(int x) { weight=x; } int main() {
Human Mike; Mike.get_stature(); //Mike.stature=2; Mike.SetStature(8); cout<<"迈克的身高"; Mike.get_stature(); Mike.SetWeight(80); cout<<"迈克的体重"; Mike.GetWeight(); return 0; }
|