⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kitchen_sink.cpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 CPP
📖 第 1 页 / 共 2 页
字号:
              << "S1/U1 : " << s1/u1 << std::endl              << std::endl;        /// check unit-unit algebra    std::cout << "U1+U1 : " << u1+u1 << std::endl              << "U1-U1 : " << u1-u1 << std::endl              << "U1*U1 : " << u1*u1 << std::endl              << "U1/U1 : " << u1/u1 << std::endl              //<< "U1+U2 : " << u1+u2 << std::endl     // illegal              //<< "U1-U2 : " << u1-u2 << std::endl     // illegal              << "U1*U2 : " << u1*u2 << std::endl              << "U1/U2 : " << u1/u2 << std::endl              << "U1^X  : " << pow<2>(u1) << std::endl              << "X1vU1 : " << root<2>(u1) << std::endl              << "U1^X2 : " << pow<static_rational<4,3> >(u1) << std::endl              << "X2vU1 : " << root<static_rational<4,3> >(u1) << std::endl              << std::endl;        /// check scalar-quantity algebra    std::cout //<< "Q1+S1 : " << q1+s1 << std::endl    // illegal              //<< "S1+Q1 : " << s1+q1 << std::endl    // illegal              //<< "Q1-S1 : " << q1-s1 << std::endl    // illegal              //<< "S1-Q1 : " << s1-q1 << std::endl    // illegal              << "Q1*S1 : " << q1*s1 << std::endl              << "S1*Q1 : " << s1*q1 << std::endl              << "Q1/S1 : " << q1/s1 << std::endl              << "S1/Q1 : " << s1/q1 << std::endl              << std::endl;        /// check unit-quantity algebra    std::cout //<< "U1+Q1 : " << u1+q1 << std::endl    // illegal              //<< "Q1+U1 : " << q1+u1 << std::endl    // illegal              //<< "U1-Q1 : " << u1-q1 << std::endl    // illegal              //<< "Q1-U1 : " << q1-u1 << std::endl    // illegal              << "U1*Q1 : " << u1*q1 << std::endl              << "Q1*U1 : " << q1*u1 << std::endl              << "U1/Q1 : " << u1/q1 << std::endl              << "Q1/U1 : " << q1/u1 << std::endl              << std::endl;        /// check quantity-quantity algebra    std::cout << "+Q1   : " << +q1 << std::endl              << "-Q1   : " << -q1 << std::endl              << "Q1+Q1 : " << q1+q1 << std::endl              << "Q1-Q1 : " << q1-q1 << std::endl              << "Q1*Q1 : " << q1*q1 << std::endl              << "Q1/Q1 : " << q1/q1 << std::endl              //<< "Q1+Q2 : " << q1+q2 << std::endl    // illegal              //<< "Q1-Q2 : " << q1-q2 << std::endl    // illegal              << "Q1*Q2 : " << q1*q2 << std::endl              << "Q1/Q2 : " << q1/q2 << std::endl              << "Q1^X1 : " << pow<2>(q1) << std::endl              << "X1vQ1 : " << root<2>(q1) << std::endl              << "Q1^X2 : " << pow<static_rational<4,3> >(q1) << std::endl              << "X2vQ1 : " << root<static_rational<4,3> >(q1) << std::endl              << std::endl;        //[kitchen_sink_snippet_2    /// check comparison tests    quantity<length>    l1(1.0*meter),                        l2(2.0*meters);    //]                            std::cout << std::boolalpha              << "l1 == l2" << "\t" << (l1 == l2) << std::endl              << "l1 != l2" << "\t" << (l1 != l2) << std::endl              << "l1 <= l2" << "\t" << (l1 <= l2) << std::endl              << "l1 < l2 " << "\t" << (l1  < l2) << std::endl              << "l1 >= l2" << "\t" << (l1 >= l2) << std::endl              << "l1 > l2 " << "\t" << (l1  > l2) << std::endl              << std::endl;        //[kitchen_sink_snippet_3    /// check implicit unit conversion from dimensionless to value_type      const double    dimless = (q1/q1);    //]        std::cout << "dimless = " << dimless << std::endl              << std::endl;                 quantity<velocity>  v1 = 2.0*meters/second;            std::cout << "v1 = " << v1 << std::endl              << std::endl;        //[kitchen_sink_snippet_4    /// test calcuation of work    quantity<force>       F(1.0*newton);    quantity<length>      dx(1.0*meter);    quantity<energy>      E(work(F,dx));    //]        std::cout << "F  = " << F << std::endl              << "dx = " << dx << std::endl              << "E  = " << E << std::endl              << std::endl;        {    //[kitchen_sink_snippet_5    /// test ideal gas law    quantity<temperature>   T = (273.+37.)*kelvin;    quantity<pressure>      P = 1.01325e5*pascals;    quantity<length>        r = 0.5e-6*meters;    quantity<volume>        V = (4.0/3.0)*3.141592*pow<3>(r);    quantity<amount>        n(idealGasLaw(P,V,T));    //]        std::cout << "r = " << r << std::endl              << "P = " << P << std::endl              << "V = " << V << std::endl              << "T = " << T << std::endl              << "n = " << n << std::endl              #if BOOST_UNITS_HAS_TYPEOF              << "R = " << constants::codata::R << std::endl              #else              << "no typeof" << std::endl              #endif // BOOST_UNITS_HAS_TYPEOF              << std::endl;    }                 //[kitchen_sink_snippet_6    /// test trig stuff    quantity<plane_angle>           theta = 0.375*radians;    quantity<dimensionless>         sin_theta = sin(theta);    quantity<plane_angle>           thetap = asin(sin_theta);    //]        std::cout << "theta            = " << theta << std::endl              << "sin(theta)       = " << sin_theta << std::endl              << "asin(sin(theta)) = " << thetap << std::endl              << std::endl;        /// test implicit conversion of dimensionless to value    double  tmp = sin_theta;        tmp = sin_theta;        /// test implicit conversion from value to dimensionless    quantity<dimensionless>     tmpp = tmp;        tmpp = tmp;        /// check complex quantities    typedef std::complex<double>    complex_type;        //[kitchen_sink_snippet_7    quantity<electric_potential,complex_type> v = complex_type(12.5,0.0)*volts;    quantity<current,complex_type>            i = complex_type(3.0,4.0)*amperes;    quantity<resistance,complex_type>         z = complex_type(1.5,-2.0)*ohms;    //]        std::cout << "V   = " << v << std::endl              << "I   = " << i << std::endl              << "Z   = " << z << std::endl              << "I*Z = " << i*z << std::endl              << std::endl;        /// check quantities using user-defined type encapsulating error propagation    //[kitchen_sink_snippet_8    quantity<length,measurement<double> >        u(measurement<double>(1.0,0.0)*meters),        w(measurement<double>(4.52,0.02)*meters),        x(measurement<double>(2.0,0.2)*meters),        y(measurement<double>(3.0,0.6)*meters);    //]                                            std::cout << "x+y-w         = " << x+y-w << std::endl              << "w*x           = " << w*x << std::endl              << "x/y           = " << x/y << std::endl              << "w*y^2/(u*x)^2 = " << w*y*y/pow<2>(u*x) << std::endl              << "w/(u*x)^(1/2) = " << w/pow< static_rational<1,2> >(u*x)              << std::endl << std::endl;    }        /// check moment of inertia/angular momentum/rotational energy        //[kitchen_sink_snippet_9    std::cout << symbol_format              << "I*w   = " << moment_of_inertia()*angular_velocity() << std::endl              << "I*w/L = " << moment_of_inertia()*angular_velocity()/angular_momentum() << std::endl              << "I*w^2 = " << moment_of_inertia()*pow<2>(angular_velocity()) << std::endl              << std::endl;    //]        //[kitchen_sink_snippet_10//    std::cout << typename_format //              << quantity<capacitance>(1.0*farad) << std::endl//              << quantity<catalytic_activity>(1.0*katal) << std::endl//              << quantity<conductance>(1.0*siemen) << std::endl//              << quantity<electric_charge>(1.0*coulomb) << std::endl//              << quantity<electric_potential>(1.0*volt) << std::endl//              << quantity<energy>(1.0*joule) << std::endl//              << quantity<force>(1.0*newton) << std::endl//              << quantity<frequency>(1.0*hertz) << std::endl//              << quantity<illuminance>(1.0*lux) << std::endl//              << quantity<inductance>(1.0*henry) << std::endl//              << quantity<luminous_flux>(1.0*lumen) << std::endl//              << quantity<magnetic_flux>(1.0*weber) << std::endl//              << quantity<magnetic_flux_density>(1.0*tesla) << std::endl//              << quantity<power>(1.0*watt) << std::endl//              << quantity<pressure>(1.0*pascals) << std::endl//              << quantity<resistance>(1.0*ohm) << std::endl//              << std::endl;    //]        //[kitchen_sink_snippet_11//    std::cout << raw_format //              << quantity<capacitance>(1.0*farad) << std::endl//              << quantity<catalytic_activity>(1.0*katal) << std::endl//              << quantity<conductance>(1.0*siemen) << std::endl//              << quantity<electric_charge>(1.0*coulomb) << std::endl//              << quantity<electric_potential>(1.0*volt) << std::endl//              << quantity<energy>(1.0*joule) << std::endl//              << quantity<force>(1.0*newton) << std::endl//              << quantity<frequency>(1.0*hertz) << std::endl//              << quantity<illuminance>(1.0*lux) << std::endl//              << quantity<inductance>(1.0*henry) << std::endl//              << quantity<luminous_flux>(1.0*lumen) << std::endl//              << quantity<magnetic_flux>(1.0*weber) << std::endl//              << quantity<magnetic_flux_density>(1.0*tesla) << std::endl//              << quantity<power>(1.0*watt) << std::endl//              << quantity<pressure>(1.0*pascals) << std::endl//              << quantity<resistance>(1.0*ohm) << std::endl//              << std::endl;    //]        //[kitchen_sink_snippet_12    std::cout << symbol_format               << quantity<capacitance>(1.0*farad) << std::endl              << quantity<catalytic_activity>(1.0*katal) << std::endl              << quantity<conductance>(1.0*siemen) << std::endl              << quantity<electric_charge>(1.0*coulomb) << std::endl              << quantity<electric_potential>(1.0*volt) << std::endl              << quantity<energy>(1.0*joule) << std::endl              << quantity<force>(1.0*newton) << std::endl              << quantity<frequency>(1.0*hertz) << std::endl              << quantity<illuminance>(1.0*lux) << std::endl              << quantity<inductance>(1.0*henry) << std::endl              << quantity<luminous_flux>(1.0*lumen) << std::endl              << quantity<magnetic_flux>(1.0*weber) << std::endl              << quantity<magnetic_flux_density>(1.0*tesla) << std::endl              << quantity<power>(1.0*watt) << std::endl              << quantity<pressure>(1.0*pascals) << std::endl              << quantity<resistance>(1.0*ohm) << std::endl              << std::endl;    //]        //[kitchen_sink_snippet_13    std::cout << name_format               << quantity<capacitance>(1.0*farad) << std::endl              << quantity<catalytic_activity>(1.0*katal) << std::endl              << quantity<conductance>(1.0*siemen) << std::endl              << quantity<electric_charge>(1.0*coulomb) << std::endl              << quantity<electric_potential>(1.0*volt) << std::endl              << quantity<energy>(1.0*joule) << std::endl              << quantity<force>(1.0*newton) << std::endl              << quantity<frequency>(1.0*hertz) << std::endl              << quantity<illuminance>(1.0*lux) << std::endl              << quantity<inductance>(1.0*henry) << std::endl              << quantity<luminous_flux>(1.0*lumen) << std::endl              << quantity<magnetic_flux>(1.0*weber) << std::endl              << quantity<magnetic_flux_density>(1.0*tesla) << std::endl              << quantity<power>(1.0*watt) << std::endl              << quantity<pressure>(1.0*pascals) << std::endl              << quantity<resistance>(1.0*ohm) << std::endl              << std::endl;    //]    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -