logo

C++'da Oran İşlemleri | Set 2 (Karşılaştırma)

Önkoşul - C++'da Oran İşlemleri | Set 1(Aritmetik)
C++'da başlık dosyası, çeşitli yerleşik şablon takma adlarını kullanarak oranları değiştirmemize olanak tanır. Başlık dosyası C++ 11'den itibaren tanıtıldı. Bu yazıda C++'da Oran Manipülasyonlarının Karşılaştırmasını tartışacağız. Aşağıdaki işlevler kullanılır:

  • oran_eşit
  • oran_eşit değil
  • oran_büyük
  • oran_less
  • oran_greater_equal
  • oran_less_equal

1. oran_eşit: Bu şablon takma adı, oranlar argümanlarında eşittir . Eşit değilse false değerini döndürürse true değerini döndürür. Bir döndürür boole üyesi devamlı 'değer'
2. oran_eşit değil: Bu şablon takma adı, oranlar onun argümanlarında eşit değil . Eşit değilse true değerini döndürür, aksi halde eşitse false değerini döndürür. Bir döndürür boole üyesi devamlı 'değer' .  



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

Çıkış
Ratios are equal Ratios are equal

3. oran_büyük: Bu geçici takma ad, oran1 oran2'den büyük . BT bir boole üyesi döndürür devamlı 'değer' oran1 oran2'den büyükse true değerini döndürür, aksi takdirde false değerini döndürür.
4. oran_sız: Bu geçici takma ad, oran1 oran2'den küçük . BT bir boole üyesi döndürür devamlı 'değer' oran1 oran2'den küçükse true değerini döndürür, aksi takdirde false değerini döndürür. 

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

Çıkış
ratio1 is not greater than ratio2 ratio1 is less than ratio2

5. oran_büyük_eşit: Bu geçici takma ad, oran1 oran2'den büyük veya eşit . BT bir boole üyesi döndürür devamlı 'değer' oran1 oran2'den büyük veya eşitse true değerini döndürür, aksi takdirde false değerini döndürür.
6. oran_az_eşit: Bu geçici takma ad, oran1 oran2'den küçük veya eşit . BT bir boole üyesi döndürür devamlı 'değer' oran1 oran2'den küçük veya ona eşitse true değerini döndürür, aksi takdirde false değerini döndürür. 

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

Çıkış
ratio1 is greater or equal than ratio2 ratio1 is less or equal than ratio2