zoukankan      html  css  js  c++  java
  • 01c++学习

    #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");
    }

    //面向对象的思路解决这问题
    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;
    }

    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");
    }

  • 相关阅读:
    读取STL模型 并用opengl显示
    金币阵列问题
    字典序问题的解决方案
    opengl中的旋转与平移
    copy文件夹,通过C++读取系统、用户名以及计算机名的方法
    poj3032
    菲涅尔反射(Fresnel Reflection)
    几个稍大场景的渲染测试
    Ward BRDF实现心得
    离线渲染中的不规则光源(Meshlight)
  • 原文地址:https://www.cnblogs.com/xinmomoyan/p/10548234.html
Copyright © 2011-2022 走看看