Ratio_less_equal function in C++


Given is the task to show the working of ratio_less_equal () function in c++.

The given function Ratio_less_equal checks if the value of ratio1 is less or equal than ratio2. It returns a Boolean constant “value” which returns true if ratio1 is less or equal than ratio2 else returns false.

Syntax

template ratio_less_equal

Parameters

This function accepts two template parameters one is ratio1 and another one is ratio2 which are to be compared.

Explanation of this function

In this function, if the value of ratio1 is less than or equal to the value of ratio2 then this function will return the Boolean value which is true i.e. integer digit 1 otherwise it will return false i.e. integer digit 0.

For Example

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.

Approach that we are using in the below program

  • first we declare the two ratios.

  • Then assign the values of two ratios.

  • Then we check if the value of ratio1 is less than or equal to value of ratio2.

  • Using ratio_less_equal we can check that

Example

// C++ code demonstrate the working of ratio_less_equal
#include<iostream.h>
#include<ratio.h>
Using namespace std;
Int main( ){
   typedef ratio<1, 3> ratio1;
   typedef ratio<3, 9> ratio2;
   if(ratio_less_equal<ratio1, ratio2>: : value)
      cout<< “ ratio1 is less than or equal to ratio2”;
   else
      cout<< “ ratio1 is not less than or equal to ratio2”;
   return 0;
}

Output

If we run the above code it will generate the following output.

1/3 is less than or equal to 3/9.
4/16 is not less than or equal to 1/4.

Updated on: 02-Mar-2020

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements