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

  • 相关阅读:
    HDU 2112 HDU Today
    HDU 1869 六度分离
    HDU 3790 最短路径问题
    HDU2066 一个人的旅行
    HDU1596 find the safest road(最短路)
    HDU 1254 推箱子(双重bfs)
    HDU 1429 胜利大逃亡(续) (bfs+状态压缩)
    HDU 1045 Fire Net
    数据结构之单链表头插法,尾插法
    Java--会移动、反弹的球
  • 原文地址:https://www.cnblogs.com/xinmomoyan/p/10548234.html
Copyright © 2011-2022 走看看