#include<iostream>
using namespace std;
const double PI = 3.14;
class circle //设计一个类
{
public://访问权限
int m_r;//半径为属性
//行为
//获取圆周长
double zhouchang() {
return 2 * PI * m_r;
}
};
int main() {
//设计一个圆类,求圆周长
circle c1;//通过圆类创建具体的圆(对象)
c1.m_r = 10;//给圆的对象属性进行具体的赋值
cout << "圆周长为" << c1.zhouchang()<< endl;
system("pause");
return 0;
}
【C++】通过类来计算圆的周长
最新推荐文章于 2023-06-17 16:36:45 发布