Az arány manipulációk C ++ -ban | 2. beállítás (összehasonlítás)

Előfeltétel - Az arány manipulációk C ++ -ban | 1. készlet (aritmetika)
C ++ -ban a A fejlécfájl lehetővé teszi számunkra, hogy az arányokat különféle beépített sablon álnevekkel manipuláljuk. A fejléc fájlt a C ++ 11 -től kezdve vezették be. Ebben a cikkben megvitatjuk az arány manipulációk összehasonlítását a C ++ -ban. A következő funkciókat használják:

  • arány_dequal
  • arány_not_equal
  • arány_greater
  • arány_ nélküli
  • arány_greater_equal
  • arány_less_equal

1. Ez a sablon álnév ellenőrzi -e a arány érveiben egyenlőek - Igaz, ha egyenlő más visszaadja a hamis visszaadást. Visszatér a logikai tag állandó 'érték'
2. arány_not_equal: Ez a sablon álnév ellenőrzi -e a arány érveiben vannak nem egyenlő - Igaz, ha nem egyenlő, ha egyenlő visszatérés hamis. Visszatér a logikai tag állandó 'érték' -  

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  ;   }   

Kibocsátás
Ratios are equal Ratios are equal 

3. arány_greater: Ez az ideiglenes álnév ellenőrzi, ha az1. - Azt Visszaad egy logikai tagot állandó 'érték' Ami igaz, ha az 1. arány nagyobb, mint az arány2, másként hamis.
4. arány_ nélküli: Ez az ideiglenes álnév ellenőrzi, ha Az 1. arány kevesebb, mint az arány2 - Azt Visszaad egy logikai tagot állandó 'érték' Ami igaz, ha az 1. arány kevesebb, mint az arány2, másként hamis. 

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  ;   }   

Kibocsátás
ratio1 is not greater than ratio2 ratio1 is less than ratio2 

5. arány_greater_equal: Ez az ideiglenes álnév ellenőrzi, ha az1. Rege az arány nagyobb vagy egyenlő, mint az arány2 - Azt Visszaad egy logikai tagot állandó 'érték' Ami igaz, ha az 1. arány nagyobb vagy egyenlő, mint a Ratio2, másként visszaadja a hamis.
6. arány_less_equal: Ez az ideiglenes álnév ellenőrzi, ha Az 1. arány kevesebb vagy egyenlő, mint az arány2 - Azt Visszaad egy logikai tagot állandó 'érték' Ami akkor tér vissza, ha az 1. arány kevesebb vagy egyenlő, mint a Ratio2, másként visszaadja a hamis. 

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  ;   }   

Kibocsátás
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2