Condition préalable - Manipulations de ratios en C++ | Ensemble 1 (arithmétique)
En C++, le
- ratio_égal
- ratio_not_equal
- ratio_plus grand
- ratio_less
- ratio_greater_equal
- ratio_less_equal
1. ratio_equal : Cet alias de modèle vérifie si le ratios dans ses arguments sont égaux . Renvoie vrai si égal, sinon renvoie faux. Il renvoie un membre booléen constante 'valeur' .
2. ratio_not_equal : Cet alias de modèle vérifie si le ratios dans ses arguments sont pas égal . Renvoie vrai si ce n’est pas égal, sinon si égal renvoie faux. Il renvoie un membre booléen constante 'valeur' .
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; }
Sortir
Ratios are equal Ratios are equal
3. ratio_plus grand : Cet alias temporaire vérifie si ratio1 est supérieur à ratio2 . Il renvoie un membre booléen constante 'valeur' qui renvoie vrai si ratio1 est supérieur à ratio2, sinon renvoie faux.
4. ratio_less : Cet alias temporaire vérifie si ratio1 est inférieur à ratio2 . Il renvoie un membre booléen constante 'valeur' qui renvoie vrai si ratio1 est inférieur à ratio2, sinon renvoie faux.
// 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; }
Sortir
ratio1 is not greater than ratio2 ratio1 is less than ratio2
5. ratio_greater_equal : Cet alias temporaire vérifie si ratio1 est supérieur ou égal à ratio2 . Il renvoie un membre booléen constante 'valeur' qui renvoie vrai si ratio1 est supérieur ou égal à ratio2, sinon renvoie faux.
6. ratio_less_equal : Cet alias temporaire vérifie si ratio1 est inférieur ou égal à ratio2 . Il renvoie un membre booléen constante 'valeur' qui renvoie vrai si ratio1 est inférieur ou égal à ratio2, sinon renvoie faux.
// 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; }
Sortir
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2