- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Ratio_greater_equal () function in C++
Given is the task to show the working of ratio_greater_equal () function in C++.
The given function Ratio_greater_equal checks if the value of ratio1 is greater or equal than ratio2. It returns a Boolean constant “value” which returns true if ratio1 is greater or equal than ratio2 else returns false.
Syntax
Template <ratio1, ratio2> ratio_greater_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 greater 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.
Explanation of typedef
Typedef is used to give data type a new name, in this program we use typedef to declare the ratios. Typedef creates the alias that can be used anywhere in place of a type name it may declare one or many identifiers on the same line and also it can be used to declare an array and function types, pointers, references, class types, etc.
For Example
Input: 1/3 and 3/9 Output: 3/9 is greater than 1/3. Input: 4/16 and 4/16 Output: 4/16 is equals to the 4/16.
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 greater than or equal to value of ratio2.
Using ratio_greater_equal we can check that
Example
// C++ code to demonstrate the working of ratio_greater_equal #include<iostream.h> #include<ratio.h> using namespace std; int main( ){ // Declaring ratios typedef ratio<10, 100> ratio1; typedef ratio<1, 10> ratio2; // Checking ratio1 is greater than or equal to ratio2. if (ratio_greater_equal<ratio1, ratio2>: : value ) cout< " ratio1 is greater than or equal to ratio2"; else cout<< " ratio1 is not greater than or equal to ratio2"; cout<< "endl"; return 0; }
Output
If we run the above code it will generate the following output
10/100 is greater than or equal to 1/10 1/3 is not greater than or equal to 3/9.