Source of multiset04.cpp


  1: //multiset3.cpp

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

  7: int main()
  8: {
  9:     cout << "\nThis program illustrates the use of a multiset to record "
 10:         "responses to a\npolling question. First we create a multiset of "
 11:         "responses, some of which\nare, of course, duplicates. Then we "
 12:         "display a summary of the responses.";
 13:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 15:     enum ResponseType
 16:     {
 17:         STRONGLY_AGREE,
 18:         AGREE,
 19:         DISAGREE,
 20:         STRONGLY_DISAGREE,
 21:         NO_OPINION
 22:     };
 23:     multiset<ResponseType> question;

 25:     //Create some responses:
 26:     question.insert(ResponseType(STRONGLY_AGREE));
 27:     question.insert(ResponseType(AGREE));
 28:     question.insert(ResponseType(STRONGLY_AGREE));
 29:     question.insert(ResponseType(STRONGLY_DISAGREE));
 30:     question.insert(ResponseType(DISAGREE));
 31:     question.insert(ResponseType(DISAGREE));
 32:     question.insert(ResponseType(NO_OPINION));
 33:     question.insert(ResponseType(AGREE));
 34:     question.insert(ResponseType(STRONGLY_AGREE));
 35:     question.insert(ResponseType(DISAGREE));
 36:     question.insert(ResponseType(DISAGREE));

 38:     //Display results:
 39:     cout << "\nRespondents that strongly agree ..... ";
 40:     cout << question.count(STRONGLY_AGREE);

 42:     cout << "\nRespondents that agree .............. ";
 43:     cout << question.count(AGREE);

 45:     cout << "\nRespondents that disagree ........... ";
 46:     cout << question.count(DISAGREE);

 48:     cout << "\nRespondents that strongly disagree .. ";
 49:     cout << question.count(STRONGLY_DISAGREE);

 51:     cout << "\nRespondents that have no opinion .... ";
 52:     cout << question.count(NO_OPINION);

 54:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 55: }