Warunek wstępny - Manipulacje współczynnikami w C++ | Zbiór 1 (arytmetyczny)
W C++
- stosunek_równy
- stosunek_nie_równy
- stosunek_większy
- stosunek_bez
- stosunek_większy_równy
- stosunek_bez_równy
1. stosunek_równy: Ten alias szablonu sprawdza, czy plik proporcje w swoich argumentach są równe . Zwraca wartość true, jeśli równa w przeciwnym razie zwraca wartość false. Zwraca a element logiczny stały 'wartość' .
2. stosunek_nie_równy: Ten alias szablonu sprawdza, czy plik proporcje w jego argumentach są nie równe . Zwraca wartość true, jeśli nie jest równa, w przypadku równości zwraca wartość false. Zwraca a element logiczny stały 'wartość' .
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; }
Wyjście
Ratios are equal Ratios are equal
3. współczynnik_większy: Ten tymczasowy alias sprawdza, czy stosunek1 jest większy niż stosunek2 . To zwraca element logiczny stały 'wartość' która zwraca wartość true, jeśli współczynnik1 jest większy niż współczynnik2, w przeciwnym razie zwraca wartość false.
4. bez stosunku: Ten tymczasowy alias sprawdza, czy stosunek1 jest mniejszy niż stosunek2 . To zwraca element logiczny stały 'wartość' która zwraca wartość true, jeśli współczynnik1 jest mniejszy niż współczynnik2, w przeciwnym razie zwraca wartość false.
// 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; }
Wyjście
ratio1 is not greater than ratio2 ratio1 is less than ratio2
5. stosunek_większy_równy: Ten tymczasowy alias sprawdza, czy współczynnik1 jest większy lub równy współczynnikowi2 . To zwraca element logiczny stały 'wartość' która zwraca wartość true, jeśli współczynnik1 jest większy lub równy współczynnikowi2, w przeciwnym razie zwraca wartość false.
6. stosunek_bez_równy: Ten tymczasowy alias sprawdza, czy współczynnik1 jest mniejszy lub równy współczynnikowi2 . To zwraca element logiczny stały 'wartość' która zwraca wartość true, jeśli współczynnik1 jest mniejszy lub równy współczynnikowi2, w przeciwnym razie zwraca wartość false.
// 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; }
Wyjście
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2