📜  C++中的比率操作|套装2(比较)

📅  最后修改于: 2021-05-30 12:52:08             🧑  作者: Mango

操纵比算法已在下面的设置1中进行了讨论

C++中的比率操作|套装1(算术)

在本文中,讨论了口粮的比较。

1. ratio_equal :-此模板别名检查其参数比率是否相等。如果相等,则返回true,否则返回false。它返回一个布尔成员常量“ value”

1. ratio_not_equal :-这个模板别名检查其参数中的比率是否不相等。如果不相等,则返回true;否则,则返回false。它返回一个布尔成员常量“ value”

// C++ code to demonstrate the working of
// ratio_equal and ratio_not_equal
#include
#include // for ratio manipulation
using namespace std;
int main()
{
    // Declaring ratios 
    typedef ratio<10, 100> ratio1;
    typedef ratio<1, 10> ratio2;
      
    // Checking if ratios are equal using ratio_equal
    ratio_equal::value ? 
              cout << "Ratios are equal" :
              cout << "Ratios are not equal";
    cout << endl;
       
     // Checking if ratios are not equal using ratio_not_equal
    ratio_not_equal::value ? 
               cout << "Ratios are not equal" :
               cout << "Ratios are equal";
      
    return 0;
      
}

输出:

Ratios are equal
Ratios are equal

3. ratio_greater :-此临时别名检查ratio1是否大于ratio2 。它返回一个布尔成员常量“值” ,如果ratio1大于ratio2,则返回true,否则返回false。

4. ratio_less :-此临时别名检查ratio1是否小于ratio2 。它返回一个布尔成员常量“值” ,如果ratio1小于ratio2,则返回true,否则返回false。

// C++ code to demonstrate the working of
// ratio_greater and ratio_less
#include
#include // for ratio manipulation
using namespace std;
int main()
{
    // Declaring ratios 
    typedef ratio<10, 100> ratio1;
    typedef ratio<11, 100> ratio2;
      
    // Checking if ratio1 is greater than ratio2 
    // using ratio_greater
    ratio_greater::value ? 
             cout << "ratio1 is greater than ratio2" :
             cout << "ratio1 is not greater than ratio2";
    cout << endl;
       
    // Checking if ratio1 is less than ratio2 
    // using ratio_less
    ratio_less::value ? 
             cout << "ratio1 is less than ratio2" :
             cout << "ratio1 is not less than ratio2";
    cout << endl;
      
    return 0;
      
}

输出:

ratio1 is not greater than ratio2
ratio1 is less than ratio2

5. ratio_greater_equal :-此临时别名检查ratio1是否大于或等于ratio2 。它返回一个布尔成员常量“值” ,如果ratio1大于或等于ratio2,则返回true,否则返回false。

6. ratio_less_equal :-此临时别名检查ratio1是否小于或等于ratio2 。它返回一个布尔成员常量“值” ,如果ratio1小于或等于ratio2,则返回true,否则返回false。

// C++ code to demonstrate the working of
// ratio_greater_equal and ratio_less_equal
#include
#include // for ratio manipulation
using namespace std;
int main()
{
    // Declaring ratios 
    typedef ratio<10, 100> ratio1;
    typedef ratio<1, 10> ratio2;
      
    // Checking if ratio1 is greater or equal than ratio2 
    // using ratio_greater_equal
    ratio_greater_equal::value ? 
           cout << "ratio1 is greater or equal than ratio2" :
           cout << "ratio1 is not greater or equal than ratio2";
    cout << endl;
       
    // Checking if ratio1 is less or equal than ratio2 
    // using ratio_less_equal 
    ratio_less_equal::value ? 
           cout << "ratio1 is less or equal than ratio2" :
           cout << "ratio1 is not less or equal than ratio2";
    cout << endl;
      
    return 0;
      
}

输出:

ratio1 is greater or equal than ratio2
ratio1 is less or equal than ratio2
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”