C++学习3 - 定义一个对象

来源:互联网 发布:win7定时开关机软件 编辑:程序博客网 时间:2024/06/05 03:49

#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


 

原创粉丝点击