c++类中属性私有设置

#include
#include
using namespace std;
class pason{
public :
	void setage(int age){
		if (age > 160) {cout << "输入错误" << endl;
		
			hage = 18;
		}
		else hage = age;
	}
	int getage(){
		return hage;
	}
	void setname(string name){
		sname = name;
	}
	string getname(){
		return sname;
	}
	void sethaoma(string haoma){
		thaoma = haoma;
	}
	string gethaoma(){
		return thaoma;
	}
private:
	int hage;
	string sname;
	string thaoma;
};
int main(){
	pason p;
	p.setage(180);
	cout << p.getage() << endl;
	p.setname("小明");
	cout << p.getname() << endl;
	p.sethaoma("1331116011");
	cout << p.gethaoma()<

你可能感兴趣的:(c++,算法,开发语言)