Ratio -manipulasjoner i C ++ | Sett 2 (sammenligning)

Forutsetning - Ratio -manipulasjoner i C ++ | Sett 1 (aritmetikk)
I C ++ Headerfil lar oss manipulere forhold ved å bruke forskjellige innebygde malalias. Hodefilen ble introdusert fra C ++ 11 og utover. I denne artikkelen vil vi diskutere sammenligningen av forholdsmanipulasjoner i C ++. Følgende funksjoner brukes:

  • Ratio_equal
  • Ratio_not_equal
  • Ratio_greater
  • Ratio_less
  • Ratio_gater_equal
  • Ratio_less_equal

1. Ratio_equal: Denne malen alias sjekker om forholdstall i sine argumenter er like . Returnerer sant hvis like annet returnerer usant. Det returnerer en boolsk medlem konstant 'verdi'
2. Ratio_not_equal: Denne malen alias sjekker om forholdstall I sine argumenter er det ikke lik . Returnerer sant hvis ikke lik annet hvis lik returnerer usant. Det returnerer en boolsk medlem konstant 'verdi' .  

CPP
   // C++ code to demonstrate the working of   // ratio_equal and ratio_not_equal   #include          #include         // for ratio manipulation   using     namespace     std  ;   // Driver Code   int     main  ()   {      // Declaring ratios      typedef     ratio   <  10       100  >     ratio1  ;      typedef     ratio   <  1       10  >     ratio2  ;      // Checking if ratios are equal using ratio_equal      ratio_equal   <  ratio1       ratio2  >::  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   <  ratio1       ratio2  >::  value      ?     cout      < <     'Ratios are not equal'      :     cout      < <     'Ratios are equal'  ;      return     0  ;   }   

Produksjon
Ratios are equal Ratios are equal 

3. Ratio_greater: Dette midlertidige aliaset sjekker om forhold1 er større enn forholdet2 . Den Returnerer et boolsk medlem konstant 'verdi' som returnerer sant hvis forhold1 er større enn forholdet2 ellers returnerer usant.
4. Ratio_less: Dette midlertidige aliaset sjekker om forhold1 er mindre enn forholdet2 . Den Returnerer et boolsk medlem konstant 'verdi' som returnerer sant hvis forhold1 er mindre enn forholdet2 ellers returnerer usant. 

CPP
   // C++ code to demonstrate the working of   // ratio_greater and ratio_less   #include          #include         // for ratio manipulation   using     namespace     std  ;   // Driver Code   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   <  ratio1       ratio2  >::  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   <  ratio1       ratio2  >::  value      ?     cout      < <     'ratio1 is less than ratio2'      :     cout      < <     'ratio1 is not less than ratio2'  ;      cout      < <     endl  ;      return     0  ;   }   

Produksjon
ratio1 is not greater than ratio2 ratio1 is less than ratio2 

5. Ratio_gater_equal: Dette midlertidige aliaset sjekker om forhold1 er større eller lik enn forholdet2 . Den Returnerer et boolsk medlem konstant 'verdi' som returnerer sant hvis forhold1 er større eller lik enn forholdet2 ellers returnerer usant.
6. Ratio_less_equal: Dette midlertidige aliaset sjekker om forhold1 er mindre eller lik enn forholdet2 . Den Returnerer et boolsk medlem konstant 'verdi' som returnerer sant hvis forhold1 er mindre eller lik enn forholdet2 ellers returnerer usant. 

CPP
   // C++ code to demonstrate the working of   // ratio_greater_equal and ratio_less_equal   #include          #include         // for ratio manipulation   using     namespace     std  ;   // Driver Code   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   <  ratio1       ratio2  >::  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   <  ratio1       ratio2  >::  value      ?     cout      < <     'ratio1 is less or equal than ratio2'      :     cout      < <     'ratio1 is not less or equal than ratio2'  ;      cout      < <     endl  ;      return     0  ;   }   

Produksjon
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2