class 类名{
????????访问权限:
????????????????属性;
????????????????方法;
}
????????类名 对象名;
????????对象名.方法名();
????????对象名.属性名;
#define PI 3.14
class Circle {
public:
float radius;
// 获取周长
float get_ZC(){
return 2*PI*radius;
}
//获取圆的面积
float get_area(){
return radius*radius*PI;
}
};
int main(){
Circle c1;
c1.radius = 10.5;
float zc,area;
zc = c1.get_ZC();
area = c1.get_area();
cout<<"周长:"<< zc<<","<<"面积:"<<area <<endl; //周长:65.94,面积:346.185
}
class Student{
public:
string s_name;
int s_age;
int s_gender=0;
private:
string s_phone_number;
public:
void set_name(string name,int age,string phone_number){
s_name = name;
s_age = age;
s_phone_number=phone_number;
cout<<"name:"<<s_name<<endl;
cout<<"age:"<<s_age<<endl;
cout<<"phone_number:"<<s_phone_number<<endl;
}
};
int main(){
Student s;
s.set_name("yoyo", 20, "13500000000");
return 1;
}