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

xiaoxiao2021-02-28  90

#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

 

转载请注明原文地址: https://www.6miu.com/read-73684.html

最新回复(0)