Manipolazioni dei rapporti in C++ | Set 2 (Confronto)

Prerequisito - Manipolazioni dei rapporti in C++ | Imposta 1 (aritmetica)
In C++ il il file header ci consente di manipolare i rapporti utilizzando vari alias modello integrati. Il file di intestazione è stato introdotto da C++11 in poi. In questo articolo discuteremo del confronto delle manipolazioni dei rapporti in C++. Vengono utilizzate le seguenti funzioni:

  • rapporto_uguale
  • rapporto_non_uguale
  • rapporto_maggiore
  • rapporto_less
  • rapporto_maggiore_uguale
  • rapporto_meno_uguale

1. rapporto_uguale: Questo alias del modello controlla se il file rapporti nelle sue argomentazioni sono uguali . Restituisce vero se uguale altrimenti restituisce falso. Restituisce a membro booleano costante 'valore'
2. rapporto_non_uguale: Questo alias del modello controlla se il file rapporti nelle sue argomentazioni sono non uguale . Restituisce vero se non uguale altrimenti se uguale restituisce falso. Restituisce a membro booleano costante 'valore' .  

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

Produzione
Ratios are equal Ratios are equal 

3. rapporto_maggiore: Questo alias temporaneo controlla se rapporto1 è maggiore di rapporto2 . Esso restituisce un membro booleano costante 'valore' che restituisce vero se rapporto1 è maggiore di rapporto2 altrimenti restituisce falso.
4. rapporto_less: Questo alias temporaneo controlla se rapporto1 è inferiore a rapporto2 . Esso restituisce un membro booleano costante 'valore' che restituisce vero se rapporto1 è inferiore a rapporto2 altrimenti restituisce falso. 

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

Produzione
ratio1 is not greater than ratio2 ratio1 is less than ratio2 

5. rapporto_maggiore_uguale: Questo alias temporaneo controlla se rapporto1 è maggiore o uguale a rapporto2 . Esso restituisce un membro booleano costante 'valore' che restituisce vero se rapporto1 è maggiore o uguale a rapporto2 altrimenti restituisce falso.
6. rapporto_meno_uguale: Questo alias temporaneo controlla se rapporto1 è inferiore o uguale a rapporto2 . Esso restituisce un membro booleano costante 'valore' che restituisce vero se rapporto1 è minore o uguale a rapporto2 altrimenti restituisce falso. 

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

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