C++ 中的 Ratio_less_equal 函数
给出了在C++中显示ratio_less_equal()函数工作的任务。
给定的函数Ratio_less_equal检查ratio1的值是否小于或等于ratio2。它返回一个布尔常量“值”,如果ratio1小于或等于ratio2,则返回true,否则返回false。
语法
template ratio_less_equal
参数
该函数接受两个模板参数,一个是ratio1,另一个是ratio2,要进行比较。
此功能的说明
在此函数中,如果ratio1的值小于或等于ratio2的值,则此函数将返回布尔值,即为真,即整数位1,否则将返回假,即整数位0。
例如
Input: 1/3 and 3/9 Output: 1/3 is less than or equal to 3/9. Input: 1/4 and 1/4 Output: 1/4 is equal to 1/4.
我们在以下程序中使用的方法
首先我们声明这两个比率。
然后分配两个比率的值。
然后我们检查ratio1的值是否小于或等于ratio2的值。
使用ratio_less_equal我们可以检查
示例
//C++代码演示ratio_less_equal的工作 #include输出结果#include Using namespace std; Int main( ){ typedef ratio<1, 3> ratio1; typedef ratio<3, 9> ratio2; if(ratio_less_equal : : value) cout<< “ ratio1 is less than or equal to ratio2”; else cout<< “ ratio1 is not less than or equal to ratio2”; return 0; }
如果我们运行上面的代码,它将生成以下输出。
1/3 is less than or equal to 3/9. 4/16 is not less than or equal to 1/4.