#include"iostream"
using namespace std;
void main01() {
//printf("hello_world
");
cout << "hello_world
" << endl;//在c++里面输出
system("pause");
}
//求圆的面积
//用面向过程的方法求解了圆形的面积
void main() {
double r = 0;
double s = 0;
//printf("hello_world
");
cout << "请输入圆的半径:";
cin >> r; //cin代表标准输入
cout << "r的值是:" << r << endl;
s = 3.14*r*r;
cout << "圆形的面积是s=" << s << endl;
system("pause");
}
![](https://img2018.cnblogs.com/blog/1542450/201903/1542450-20190317110136796-1719686417.png)
//面向对象的思路解决这问题
class CirCle {
private:
double m_s;
double m_r;
double m_c;
public:
void setR(double r) {
this->m_r = r;
}
double getR() {
return this->m_r;
}
double getS() {
return this->m_r * m_r * 3.14;
}
double getC() {
return this->m_r * 2 * 3.14;
}
};
int main() {
CirCle c1, c2;
double r,r2;
cout << "输入c1圆的半径" ;
cin >> r;
c1.setR(r);
cout << "c1圆的面积是" << c1.getS() <<endl;
cout << "c1元的周长是" << c1.getC() << endl;
cout << "输入c2圆的半径" ;
cin >> r2;
c2.setR(r2);
cout << "c2圆的面积是" << c2.getS() << endl;
cout << "c2元的周长是" << c2.getC() << endl;
system("pause");
return 0;
}
![](https://img2018.cnblogs.com/blog/1542450/201903/1542450-20190317112051453-1860495410.png)
c++中的命名空间
#include "iostream"
using namespace std;
//定义命名空间
namespace namespaceA {
int a = 10;
}
namespace namespaceB {
int a = 20;
}
//使用命名空间
void main() {
using namespace namespaceA;
cout << a << endl;
cout << namespaceB::a << endl;
system("pause");
}
![](https://img2018.cnblogs.com/blog/1542450/201903/1542450-20190317121723253-1288665457.png)