logo

C++의 비율 조작 | 세트 2 (비교)

전제 조건 - C++의 비율 조작 | 세트 1(산술)
C++에서는 헤더 파일을 사용하면 내장된 다양한 템플릿 별칭을 사용하여 비율을 조작할 수 있습니다. 헤더 파일은 C++11부터 도입되었습니다. 이 기사에서는 C++의 비율 조작 비교에 대해 설명합니다. 다음 기능이 사용됩니다:

  • 비율_같음
  • ratio_not_equal
  • 비율_이상
  • 비율_없음
  • ratio_greater_equal
  • ratio_less_equal

1. 비율_동등: 이 템플릿 별칭은 비율 그 주장에서 동등하다 . 같으면 true를 반환하고, 그렇지 않으면 false를 반환합니다. 그것은 부울 멤버 끊임없는 '값'
2. ratio_not_equal: 이 템플릿 별칭은 비율 그 주장에는 같지 않다 . 같지 않으면 true를 반환하고 같으면 false를 반환합니다. 그것은 부울 멤버 끊임없는 '값' .  



네트워킹 및 유형
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; } 

산출
Ratios are equal Ratios are equal

3. 비율_이상: 이 임시 별칭은 다음을 확인합니다. 비율1이 비율2보다 큽니다. . 그것 부울 멤버를 반환합니다. 끊임없는 '값' ratio1이 ratio2보다 크면 true를 반환하고 그렇지 않으면 false를 반환합니다.
4. 비율 없음: 이 임시 별칭은 다음을 확인합니다. ratio1은 ratio2보다 작습니다. . 그것 부울 멤버를 반환합니다. 끊임없는 '값' ratio1이 ratio2보다 작으면 true를 반환하고 그렇지 않으면 false를 반환합니다. 

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

산출
ratio1 is not greater than ratio2 ratio1 is less than ratio2

5. ratio_greater_equal: 이 임시 별칭은 다음을 확인합니다. ratio1은 ratio2보다 크거나 같습니다. . 그것 부울 멤버를 반환합니다. 끊임없는 '값' ratio1이 ratio2보다 크거나 같으면 true를 반환하고, 그렇지 않으면 false를 반환합니다.
6. ratio_less_equal: 이 임시 별칭은 다음을 확인합니다. ratio1은 ratio2보다 작거나 같습니다. . 그것 부울 멤버를 반환합니다. 끊임없는 '값' ratio1이 ratio2보다 작거나 같으면 true를 반환하고 그렇지 않으면 false를 반환합니다. 

샘플 자바 코드
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; } 

산출
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2