Source of set17.cpp


  1: //set17.cpp

  3: #include <iostream>
  4: #include <iomanip>
  5: #include <set>
  6: using namespace std;

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the comparison of sets using "
 11:         "the relational operators.";
 12:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 14:     char a[] = {'A', 'B', 'C', 'D', 'E'};
 15:     set<char> s1(a, a+4);
 16:     set<char> s2(a, a+5);
 17:     set<char> s3(a, a+5);

 19:     cout << "\nWe begin by creating three sets.";
 20:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 22:     cout << "\nHere are the values in the first set:\n";
 23:     set<char>::iterator p = s1.begin();
 24:     while (p != s1.end()) cout << *p++ << " ";
 25:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 27:     cout << "\nHere are the values in the second set:\n";
 28:     p = s2.begin();
 29:     while (p != s2.end()) cout << *p++ << " ";
 30:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 32:     cout << "\nThe contents of the third set are the same as the second.";
 33:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 35:     cout << "\nNow we perform and show the results of some "
 36:         "set comparisons.";
 37:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 39:     cout << "\ns1 < s2  = " << boolalpha << (s1 < s2);
 40:     cout << "\ns1 <= s2 = " << boolalpha << (s1 <= s2);
 41:     cout << "\ns1 > s2  = " << boolalpha << (s1 > s2);
 42:     cout << "\ns1 >= s2 = " << boolalpha << (s1 >= s2);
 43:     cout << "\ns2 == s3 = " << boolalpha << (s2 == s3);
 44:     cout << "\ns2 != s3 = " << boolalpha << (s2 != s3);
 45:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 46: }