C++學習3 - 定義一個對象

#include<iostream>
using namespace std;

class People{
public:
 void getStature(){
  cout <<"Zing的升高爲:"<<stature<<"cm"<<endl;
 }
 void getWeight();
 void setStature(int x){
  stature = x;
 }
 void setWeight(int y);
private:
 int stature = 0;
 int weight = 0;
};
void People::getWeight(){
 cout << "Zing的體重爲:" << weight << "kg" << endl;
}
void People::setWeight(int y){
 weight = y;
}
void main(){
 People Zing;
 Zing.setStature(179);
 Zing.setWeight(60);
 Zing.getStature();
 Zing.getWeight();
 system("pause");
}

 


更多詳情請點擊  http://blog.sina.com.cn/zhaojianjunzjj


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章